本文介绍了该代码以嵌套的"if scores in scores"返回语法错误.陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的嵌套if语句导致语法错误,我不明白为什么.
The nested if statement below is causing a syntax error and I can not see why.
scores = []
choice = None
while choice != 0:
print(
"""
High Scores
0 - Exit
1- Show Scores
2- Add a Score
3 -Delete a Score
4- Sort Scores
"""
)
#take use input
choice = input("Choice:")
if choice == 0:
print ("Good Bye")
elif choice == 1:
print ("High Scores")
for score in scores:
print(score)
elif choice == 2:
score = input("What score did you get? : ")
scores.append(score)
elif choice == 3:
score =int(input("What score do you want to be removed?:")
if score in scores: <<<------ this line is causing the syntax error
scores.remove(score)
else:
print("The specified score is not in the list.")
elif choice == 4:
score.sort(reverse = True)
print(scores)
else:
print("Sorry, but", choice, "is not valid.")
推荐答案
您需要关闭上一行的 int()
括号.
You need to close the int()
parentheses on the line above.
score =int(input("What score do you want to be removed?:"))
这篇关于该代码以嵌套的"if scores in scores"返回语法错误.陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!