这是代码:
# Guess the word program
# By Roxmate
# 12/04/2013
import random
print \
"""\t\t\t ***Welcome to Guess the Word Program***
Your goal is to guess what word the computer has chosen and
you have 5 hints per guess, just type help to get the first one.
If you wish to exit the program, type in exit.
\t\t\tGood Luck!
"""
WORDS = ("book","house","universe")
gen_word = random.choice(WORDS)
gen_word_1 = len(gen_word)
hint_letter = random.choice(gen_word)
hint = "help"
quit_game = "exit"
print "The word that the computer choosed has", gen_word_1, "letters\n"
guess = raw_input("Your Guess:")
while guess != quit_game:
if guess == gen_word:
print "Congrats, you have guessed the word!"
break
elif guess == hint:
print "Hint:: There is a(n)", hint_letter, "in the word\n"
else:
if guess != gen_word:
print "I am sorry that's not the word, try again.\n"
guess = raw_input("Your Guess:")
raw_input()
问题是在
elif guess == hint:
print "Hint:: There is a(n)", hint_letter, "in the word\n"
我不明白为什么它只给出相同的字母作为提示,它不应该在每次循环运行时从单词中随机选择一个字母吗?例如,我输入帮助,它给了我a,下次我输入帮助它会给我b。