2 回答
TA贡献1798条经验 获得超7个赞
您的内环缩进得太远。 前面有 5 个空格,而其他所有内容都缩进 4 个空格。另外,当我们谈论缩进时,您也有一个不正确的缩进。while True:
break
要解决此问题,请执行以下操作:
从之前删除一个空格
while True:
在之前再添加三个空格
break
对于奖励积分,还要从嵌套内的5行之前删除一个空格,以便它们缩进8或12个空格。
while
更新问题的提示:
看看你的内部循环的实现。在什么情况下程序会退出该循环以继续?test_score = ...
TA贡献1831条经验 获得超9个赞
下面编辑的代码可能会有所帮助,这可能就是您想要做的。
print("The Test Scores application")
print()
print("Enter test scores")
print("Enter end to end input")
print("======================")
# initialize variables
counter = 0
score_total = 0
test_score = 0
get_entries = 'y'
while test_score != 999:
while True:
get_entries = input("Get entries for another set of scores? ")
if get_entries == 'y':
print("Enter your information below")
else:
print("Thank you for using the Test Scores application. Goodbye!")
break
test_score = input("Enter test score: ")
if test_score == 'end':
break
elif (int(test_score) >= 0) and (int(test_score) <= 100):
score_total += int(test_score)
counter += 1
elif test_score == 999:
break
else:
print("Test score must be from 0 through 100. Score discarded. Try again.")
break
# calculate average score
average_score = round(score_total / counter)
# format and display the result
print("======================")
print("Total Score:", score_total,
"\nAverage Score:", average_score)
添加回答
举报