osx - Python 2.7 Program not working in MAC terminal -
i teaching intro coding class students , attempting run next program. giving syntax error. here both programme , error message:
# introduction print 'hello. if give me scores, can find overall grade.' ques = raw_input('would me find class grade? y/n ') # first score if ques in ['y', 'y', 'yes', 'yes']: count = 1 sum = int(raw_input('what first score? ') ans = raw_input('do have score me? y/n ') else: ans = 'no' print 'thanks anyway. run me later if alter mind.' # other scores while ans in ['y', 'y', 'yes', 'yes']: sum = sum + int(raw_input('what next score? ') count = count + 1 ans = raw_input('do have score 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 have score me? y/n ') ^ syntaxerror: invalid syntax logout [process completed]
you missing closing parenthesis on preceding line:
sum = int(raw_input('what next score? ') # ^ ^ ^^ ? # | \-------- matched -------/ | # \-------------- missing --------------/
you 1 time again later on in program:
sum = sum + int(raw_input('what next score? ') # ^ ^ ^^ ? # | \-------- matched -------/ | # \-------------- missing --------------/
you may want take @ asking user input until give valid response tips on how handle user input better.
python osx python-2.7 terminal
No comments:
Post a Comment