i wrote a code in python 3 and there is an unexpected syntax error in the elif statement

+1 vote
asked Aug 3, 2018 by anonymous

I am currently taking the edx course for python beginners and this is the final coding assesment test. my code is the following and the error is in line 19 :   elif report_type.upper().startswith("T"):

It is a syntax error but the break statement above makes it happen because i have removed it, along with the while True loop and it runs perfectly

Any assistance would be appreciated.

total= 0
numbers = "\nItems\n"
print('Report Types include ALL Items ("A") or Total Only ("T")')
while True:
    report_type= input('Choose Report Type ("A" or "T"): ')
    if report_type.upper().startswith("A"):
        while True:
            x=input('Input an integer to add to the total or "Q" to quit: ')
            if x.isdigit()==True:
                total += int(x)
                numbers += x + "\n"
            elif x.upper().startswith("Q"):
                print(numbers)
                print("\nTotal\n",total)
                break
            else:
                print(x,"is invalid input")
    break
    elif report_type.upper().startswith("T"):
        while True:
            x=input('Input an integer to add to the total or "Q" to quit: ')
            if x.isdigit()==True:
                total += int(x)
            elif x.upper().startswith("Q"):
                print("\nTotal\n",total)
                break
            else:
                print(x,"is invalid input")
    break
    else:
        print(report_type,"is invalid input")

I am sorry for any indentation issues i had to do it with the spacebar.

1 Answer

+1 vote
answered Aug 10, 2018 by Nanda
The break statement on line 18 and 19 are not in correctly intended with while statements. Correct it and check
commented Dec 11, 2018 by Tomas Z (180 points)
same for line 29, you need two indents (tabs) before this break
->->break
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...