我想创建一个游戏,在这个游戏中电脑选择一个随机单词,玩家必须猜测这个单词。然后计算机会告诉玩家这个词有多少个字母。然后玩家有五次机会问一个字是否在这个单词中。电脑只能回答“是”或“否”。然后,玩家必须猜测这个词。为什么我的变量在python中不起作用
不知何故,下面我写的程序并没有准确地给玩家5个机会在让玩家猜测该单词之前询问该单词是否在单词中。我可以知道出了什么问题吗?谢谢!
import random
WORDS = ("hello", "running", "help", "united")
word = random.choice(WORDS)
correct = word
letters=len(word)
print "There are", len(word), "letters in the word. You have 5 chances to guess the letter in the word. After which you will be required to guess the word."
guess_letter = raw_input("Guess a letter in the word.")
tries = 0
while guess_letter in word:
tries +=1
print "Yes"
guess_letter = raw_input("Guess another letter in the word.")
if tries == 4:
print "Please guess the word."
answer = raw_input("What is the word?")
if answer == correct:
print "That is correct!"
else:
print "You lose."
while guess_letter not in word:
tries +=1
print "No"
guess_letter = raw_input("Guess another letter in the word.")
if tries == 4:
print "Please guess the word."
answer = raw_input("What is the word?")
if answer == correct:
print "That is correct!"
else:
print "You lose."
请解决您的缩进 – MattDMo 2015-03-13 16:31:35
如果你只是你为什么不使用'为loop'而是有5种变化? – 2015-03-13 16:34:54