Python Forum
Trouble with edX Python Final
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with edX Python Final
#11
def adding_report(report = "T"):
    total = 0
    numbers = "\nItems\n"
    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.startswith("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()
adding_report("T")
adding_report("A")
Didn't notice that typo, fixed it! Thank you. It's not running again now for some reason, and I have no idea why. I called the function and fixed the syntax errors from before, but when I try to run the code (provided above) it won't run at all, it just jumps to the next cell.
Reply
#12
If this question is still open I'd like to mention a few points:
  1. You are calling adding_report(int_or_q) again in the function definition (line 21). There is no need for this and this would cause the function to be called recursively.
  2. You don't need the second 'if' condition. You are handling this in line 13 and 14
This should make your code work as expected.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python trouble #1 Cicada3301 5 2,068 Nov-17-2021, 09:35 PM
Last Post: Cicada3301
Smile Final Projet - Credit Risk Rauchvant 3 2,375 Nov-18-2020, 03:21 PM
Last Post: Rauchvant
  Help needed, stuck at the final output extricate 0 1,513 Jun-20-2020, 05:35 AM
Last Post: extricate
  Final Project (Databases, GUI, and Classes) poochenthecreator 1 1,616 Apr-27-2020, 09:58 PM
Last Post: deanhystad
  Final Project Help hyg71886 6 3,889 Feb-07-2019, 01:30 AM
Last Post: micseydel
  Final problem Truman 4 3,980 Jan-22-2018, 11:42 PM
Last Post: Truman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020