2 回答

TA貢獻1798條經(jīng)驗 獲得超7個贊
您的內(nèi)環(huán)縮進得太遠。 前面有 5 個空格,而其他所有內(nèi)容都縮進 4 個空格。另外,當我們談?wù)摽s進時,您也有一個不正確的縮進。while True:
break
要解決此問題,請執(zhí)行以下操作:
從之前刪除一個空格
while True:
在之前再添加三個空格
break
對于獎勵積分,還要從嵌套內(nèi)的5行之前刪除一個空格,以便它們縮進8或12個空格。
while
更新問題的提示:
看看你的內(nèi)部循環(huán)的實現(xiàn)。在什么情況下程序會退出該循環(huán)以繼續(xù)?test_score = ...

TA貢獻1831條經(jīng)驗 獲得超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)
添加回答
舉報