The code returns syntax error in nested “if score in scores:” statement [closed]

放肆的年华 提交于 2019-12-13 10:54:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!