代码在嵌套的“if score in scores:”语句中返回语法错误

2024-03-29 07:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的嵌套if语句导致语法错误,我不知道原因。你知道吗

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.")

Tags: theinyouinputifiswhatscore