问题
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.")
回答1:
You need to close the int()
parentheses on the line above.
score =int(input("What score do you want to be removed?:"))
来源:https://stackoverflow.com/questions/41706555/the-code-returns-syntax-error-in-nested-if-score-in-scores-statement