Hello Everyone,
I am currently taking the edX course "Introduction to Python: Absolute Beginner" through Microsoft (Course ID DEV236x), and am having trouble getting the code to run for my final assignment.
Here are the instructions ---------------------------------------------------------------------------------
Program: adding_report() function
This program calls the adding_report() function which repeatedly takes positive integer input until the user quits and then sums the integers and prints a "report".
The adding_report() function has 1 string parameter which indicates the type of report:
"A" used as the argument to adding_report() results in printing of all of the input integers and the total
"T" used as the argument results in printing only the total
Sample input and output:
call adding_report() with "A" as argument (print all the integers entered and the total)
Input an integer to add to the total or "Q" to quit
Enter an integer or "Q": 3
Enter an integer or "Q": 6
Enter an integer or "Q": 24
Enter an integer or "Q": 17
Enter an integer or "Q": 61
Enter an integer or "Q": nine
nine is invalid input
Enter an integer or "Q": q
Items
3
6
24
17
61
Total
111
call with "T"(print only the total)
Input an integer to add to the total or "Q" to quit
Enter an integer or "Q": 5
Enter an integer or "Q": 7
Enter an integer or "Q": Quit
Total
12
And here is my code so far --------------------------------------------------------------------------------
I can't figure out what is wrong with my program, whenever I try to run it nothing happens -- I don't even receive a message about a specific error. Any guidance would be greatly appreciated, thank you!
I am currently taking the edX course "Introduction to Python: Absolute Beginner" through Microsoft (Course ID DEV236x), and am having trouble getting the code to run for my final assignment.
Here are the instructions ---------------------------------------------------------------------------------
Program: adding_report() function
This program calls the adding_report() function which repeatedly takes positive integer input until the user quits and then sums the integers and prints a "report".
The adding_report() function has 1 string parameter which indicates the type of report:
"A" used as the argument to adding_report() results in printing of all of the input integers and the total
"T" used as the argument results in printing only the total
Sample input and output:
call adding_report() with "A" as argument (print all the integers entered and the total)
Input an integer to add to the total or "Q" to quit
Enter an integer or "Q": 3
Enter an integer or "Q": 6
Enter an integer or "Q": 24
Enter an integer or "Q": 17
Enter an integer or "Q": 61
Enter an integer or "Q": nine
nine is invalid input
Enter an integer or "Q": q
Items
3
6
24
17
61
Total
111
call with "T"(print only the total)
Input an integer to add to the total or "Q" to quit
Enter an integer or "Q": 5
Enter an integer or "Q": 7
Enter an integer or "Q": Quit
Total
12
And here is my code so far --------------------------------------------------------------------------------
def adding_report(report = "T"): total = 0 numbers = "\nItems\n" print = input("Enter an integer, or 'Q'' to quit: ") while True: int_or_q = input("Enter an integer, or 'Q' to quit: ") if int_or_q.isdigit(): total += int(int_or_q) if report.startswith("A"): numbers += int_or_q + "\n" elif int_or_q.startswith("Q"): if report.startwith("A"): print(numbers + "\nTotal\n" + str(total)) else: print("\nTotal\n" + str(total)) break if report.startswith("T"): print("\nTotal\n" + str(total)) else: print(int_or_q, "is an invalid input, try again!") break adding_report(int_or_q) print()
I can't figure out what is wrong with my program, whenever I try to run it nothing happens -- I don't even receive a message about a specific error. Any guidance would be greatly appreciated, thank you!