运行此程序时,我收到此错误消息: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 = TruewordList = secretWordplayAgain = 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()
1 回答

RISEBY
TA贡献1856条经验 获得超5个赞
我看到你在重新开始游戏时遇到了麻烦。简单地调用您的函数不会重新启动整个游戏或将您带回顶部,但您可以进行的一个小调整是将所有内容放入while具有这样条件的循环中
play = 'y'
while play == 'y':
words = "Harry John Paul Jane Sue Frank Julie Tom Alice Sam".split()
....
playAgain = input("Do you want to play again? (yes or y) to continue")
if playAgain == "Yes" or playAgain == "y":
play = 'y'
continue
else:
print("Ok. Goodbye.")
play = 'n'
所有这一切都是,如果play的值为 ,则y游戏将重播,直到值更改为 ,n然后循环将结束,因此游戏
添加回答
举报
0/150
提交
取消