运行此程序时,我收到此错误消息:NameError: name 'wordList' is not defined。想不通为什么。谢谢。
随机导入
定义主():
def getRandomWord(wordList):
wordIndex = random.randint(0, len(wordList) -1)
return wordList[wordIndex]
words = "Harry John Paul Jane Sue Frank Julie Tom Alice Sam".split()
secretWord = getRandomWord(words)
print("Welcome to You Bet Your Life with Groucho\n")
print("Say the secret word and win a thousand dollars!")
your_word = input("What is your guess for the secret word? ")
if your_word == secretWord:
print("Congratulations you are correct. The secrt word is", secretWord)
print("and you win $1000 dollars !")
else:
print("Sorry, that is not the secret word.")
playAgain = True
wordList = secretWord
playAgain = input("Do you want to play again? (yes or y) to continue")
if playAgain == "Yes" or playAgain == "y":
getRandomWord(wordList)
else:
print("Ok. Goodbye.")
如果名称== ' main ': main()
RISEBY
相关分类