【发布时间】:2014-06-18 15:31:27
【问题描述】:
我正在为学生教授编码课程的介绍,我们正在尝试运行以下程序。它给出了语法错误。以下是程序和错误信息:
# 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
错误信息:
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]
【问题讨论】:
标签: python macos python-2.7 terminal