我刚开始用python编程,我正在根据一本书编写一个刽子手游戏。我能知道为什么我下面的代码没有按照我想要的顺序运行吗?在
当我执行程序时,guess中猜测的字母应该进入used,以表明哪些字母已经被播放机猜测出来,以找出正确的单词。但是,这种情况只发生在每2圈,而不是每1圈。我已经在一个图像文件中指明了hangman ACSII程序的开始部分,以供参考,图像下方是代码。非常感谢您的帮助。谢谢!在
MAX_WRONG = len(HANGMAN)-1
WORDS = ("book","toy","paper","school","house","computer","television")
word=random.choice(WORDS)
so_far = "-"*len(word)
wrong = 0
used = []
print "Welcome to hangman! Guess the the word before the the man is hang dead!"
print "You can only guess one letter at a time!"
while wrong < MAX_WRONG and so_far!=word:
print HANGMAN[wrong]
print "\nYou've used the following letters:\n",used
print "\nSo far, the word is:\n", so_far
guess = raw_input("\n\nEnter your guess:")
guess = guess.lower()
if guess in word:
used+=guess
print "\nYou've used the following letters:\n",used
print"\nYes!",guess,"is in the word!"
new=""
for i in range(len(word)):
if guess == word[i]:
new+=guess
else:
new+=so_far[i]
so_far=new
else:
used+=guess
print "\nYou've used the following letters:\n",used
print "\nSo far, the word is:\n", so_far
print"\nSorry,",guess,"isn't in the word."
guess = raw_input("\n\nEnter your guess:")
wrong+=1
while guess in used:
print "You've already guessed the letter:",guess
print "\nYou've used the following letters:\n",used
print "\nSo far, the word is:\n", so_far
guess = raw_input("Enter your guess:")
guess = guess.lower
if wrong == MAX_WRONG:
print HANGMAN[wrong]
print "\nYou've been hanged!"
else:
print "\nYou guessed it!"
print "\nThe word was",word
raw_input("\n\nPress the enter key to exit.")