Hangman游戏 - 在while循环中的错误

时间:2016-11-28 14:41:23

标签: python

我已经在python上创建了一个刽子手游戏,但它似乎没有工作...... 这是代码:

guessed = ''

lives = 7

while lives > 0:

    missed = 0
    print()
    for letter in generated_word:
        if letter in guessed:
            pritn (letter,end=' ')
        else:
            print ('_',end=' ')
            missed = missed + 1
    if missed == 0:
        print ('You win!')  
        quit()
        break
    guess=input("please guess a letter:")


    guessed = guessed + guess
    if guess not in generated_word:

        print ('\n That letter is not in this word, your lives have been decreased by 1.')
        print ('Please try another letter.')
        lives = lives - 1 
        missed = missed + 1

        print('your new lives value is')

        print(lives)

        if lives < 7:
            print('''   _______
   |    |   ''')
            if lives < 6:
                print('   |    O    ') 
            if lives < 5:            
                print('   |    |    ')
            if lives < 4:
                print('   |  \- -/  ')
            if lives < 3: 
                print('   |    |    ')
            if lives < 2:
                print('   |   / \\  ')
            if lives < 1:
                print('   |  /   \\ ')
            if lives == 0:
             print('___|___      ')
             print('GAME OVER! You have run out of lives and lost the game')
             print('The random word was...')
             print(generated_word)
             quit()

有什么帮助吗?它说打印没有定义? 我是新手并且犯了很多错误,如果有人能纠正这段代码,我将不胜感激。

2 个答案:

答案 0 :(得分:0)

您在其中一个打印语句中犯了拼写错误:

missed = 0
print()
for letter in generated_word:
    if letter in guessed:

这是拼写错误

        print (letter,end=' ')

这是你的其余代码

    else:
        print ('_',end=' ')
        missed = missed + 1
if missed == 0:
    print ('You win!')  
    quit()
    break
guess=input("please guess a letter:")

这应该修复该部分。

答案 1 :(得分:0)

我很确定这是另一项家庭作业,因为类似的“刽子手”问题在过去2周内被问过4/5次。你有一些错误:

1)您没有为generated_word分配任何值,因此当您尝试运行for循环时会发生错误。您应该创建随机单词列表,然后随机访问它们并将其分配给generated_words

2)while循环中的第二个打印语句拼写错误。