Python Forum
Help, Syntax error on except statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help, Syntax error on except statement
#1
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)
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
as ichabod801 said you should always post full traceback. But in this case it's clear there is missing closing parenthesis on line 11.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,013 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 334 Jan-19-2024, 01:20 PM
Last Post: rob101
  An unexplainable error in .format statement - but only in a larger piece of code? ToniE 4 656 Sep-05-2023, 12:50 PM
Last Post: ToniE
  Syntax error while executing the Python code in Linux DivAsh 8 1,454 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,137 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,251 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,777 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Error in Using INPUT statement gunwaba 1 2,017 Jul-03-2022, 10:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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