TypeError: argument of type 'NoneType' is not iterable

前端 未结 2 943
攒了一身酷
攒了一身酷 2020-12-28 11:01

I am making a Hangman game in Python. In the game, one python file has a function that selects a random string from an array and stores it in a variable. That variable is th

2条回答
  •  轮回少年
    2020-12-28 11:08

    The python error says that wordInput is not an iterable -> it is of NoneType.

    If you print wordInput before the offending line, you will see that wordInput is None.

    Since wordInput is None, that means that the argument passed to the function is also None. In this case word. You assign the result of pickEasy to word.

    The problem is that your pickEasy function does not return anything. In Python, a method that didn't return anything returns a NoneType.

    I think you wanted to return a word, so this will suffice:

    def pickEasy():
        word = random.choice(easyWords)
        word = str(word)
        for i in range(1, len(word) + 1):
            wordCount.append("_")
        return word
    

提交回复
热议问题