Python Forum

Full Version: Help, Syntax error on except statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi im recently new to python and was coding for my homework and when I tried to run my program it gives me n error on the except statement. im currently using version 3.7.1


Here's the code (Python)


count = 0
total = 0
mean = 0
while True:
    command = input('Enter a number: ') 
    if command == 'done':
        break
    try:
        count = count + 1
        total =  total + float(command)
        mean = float (total/float (count)

    except:
        count = count - 1
        print ('invalid input, please enter a valid number')

print ('You have entered : ',count,'numbers')
print ('the total of your numbrs is : ', total)
print ('The mean of your numbers is : ',mean)
You should post the full text of the error when you get one. In this case I know it was a syntax error, but it took me a bit to figure that out. You are missing a close parentheses at the end of line 11. That doesn't become a syntax error until the except statement. When dealing with syntax errors, always check the previous line as well as the line the error shows up on.
as ichabod801 said you should always post full traceback. But in this case it's clear there is missing closing parenthesis on line 11.