简体   繁体   中英

I've found this 3-letter game, but when I tried to run the program, my screen says that the 7th line has an error

My screen says that the 7th line has a syntax error. Any ideas why?

words = []

game = "play"

while game == "play":

new = input("Enter a 3-letter word: ")

if len(new) > 3 or len(new) < 3:

    print("That's not a 3-letter word.")

else:
    if new in words:
        game = "over"
        print("You already said that word, Game Over.")

        print("You know", len(words), "3-letter words.

Python uses indentation instead of parenthesis or rackets to mark the beginning and end of statements such as if, or for or in this case while. All you need to do is to include a tab in all the lines that are supposed to be after the while and that should work fine:

words = []

game = "play"

while game == "play":

    new = input("Enter a 3-letter word: ")

    if len(new) > 3 or len(new) < 3:

        print("That's not a 3-letter word.")

    else:
        if new in words:
            game = "over"
            print("You already said that word, Game Over.")

            print("You know", len(words), "3-letter words.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM