0

I am teaching an intro to coding class for students and we are attempting to run the following program. It is giving a syntax error. Here are both the program and error message:

# Introduction
print 'Hello. If you give me your scores, I can find your overall grade.'
ques = raw_input('Would you like me to find your class grade? y/n ')


# Get first score
if ques in ['y', 'Y', 'yes', 'Yes']:
    count = 1
    sum = int(raw_input('What is your first score? ')
    ans = raw_input('Do you have another score for me? y/n ')
else:
    ans = 'no'
    print 'Thanks anyway. Run me later if you change your mind.'

# Get other scores
while ans in ['y', 'Y', 'yes', 'Yes']:
    sum = sum + int(raw_input('What is the next score? ')
    count = count + 1
    ans = raw_input('Do you have another score for me? y/n ')

# Calculate score
avg = sum / count
print 'Your class grade is:', avg

Error message:

Last login: Wed Jun 18 10:07:31 on ttys000
D-iMac-00:~ prog$ /var/folders/1r/zxdwc24s2h5gncz_q09x46rw0000gq/T/Cleanup\ At\ Startup/fancy_grade-424798099.021.py.command ; exit;
  File "/Users/prog/Desktop/Jake/fancy_grade.py", line 10
    ans = raw_input('Do you have another score for me? y/n ')
      ^
SyntaxError: invalid syntax
logout

[Process completed]
JakeG
  • 13
  • 3

2 Answers2

1

You are missing a closing parenthesis on a preceding line:

sum = int(raw_input('What is the next score? ')
#        ^         ^                          ^^ ?
#        |          \-------- matched -------/ |
#         \-------------- missing --------------/

You do so again later on in the program:

sum = sum + int(raw_input('What is the next score? ')
#              ^         ^                          ^^ ?
#              |          \-------- matched -------/ |
#              \-------------- missing --------------/

You may want to take a look at Asking the user for input until they give a valid response for tips on how to handle user input better.

Community
  • 1
  • 1
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

You are missing a ")" on line 9. Syntax errors are usually related to things like that.

hazzey
  • 1,179
  • 25
  • 29