python程序的运行顺序_为什么我的python程序没有按正确的顺序运行代码?

在尝试编写刽子手游戏时,遇到了一个问题:代码中猜到的字母应该每次输入后就加入到已使用字母列表,但实际只有每两轮才加入。代码包括设置最大错误次数、选择随机单词、初始化进度条和已使用字母列表等。通过用户的输入和条件判断更新游戏状态,但输入检查和更新环节存在逻辑问题导致顺序不正确。
摘要由CSDN通过智能技术生成

我刚开始用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.")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值