我对我创建的函数有问题,它不会停止,有人能建议我做错了什么吗?你知道吗
import random
words = ["monitor", "mouse", "CPU", "keyboard"]
attempts = []
randomWord = random.choice(words)
noChar = len(randomWord)
print randomWord , noChar
print "Hello, Welcome to the game of Hangman. You have to guess the given word. The first word has", noChar, " letters."
def game():
guess = raw_input ("Please choose letter")
attempts.append(guess)
print (attempts)
if guess in randomWord:
print "You have guessed the letter"
else:
print "Please try again"
return()
chance = raw_input ("Have a guess")
while chance!= randomWord:
game()
请求猜测的输入需要在
game
函数内部或每次完成时触发多次。你知道吗你只是在游戏开始时要求
chance
。除非玩家立即猜出单词,否则不会触发胜利条件。你知道吗像这样的事情会解决的:
额外提示:要按顺序打印所有成功的猜测,即按照它们在隐藏单词中的顺序,您可以执行以下操作:
将输出:
这样玩家就可以看到正确字母的顺序。你知道吗
相关问题 更多 >
编程相关推荐