2016-11-28 61 views
-3

我HVE創建Python的劊子手遊戲,但它似乎沒有工作... 這裏的代碼:劊子手遊戲 - 錯誤while循環

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() 

任何幫助嗎?它說打印沒有定義? 我是新手,有很多錯誤,如果有人能更正此代碼,我將不勝感激。

+1

你使用的是什麼版本的Python?另外,請發佈錯誤的完整文本(如果您有一個堆棧跟蹤)。 – khelwood

+1

打印被定義,pritn不是。 – polku

+1

似乎你已經向generated_word聲明瞭任何值 – Inconnu

回答

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:") 

這應該修復該部分。

+0

你能準確指定拼寫錯誤的位置嗎? – user2728397

+0

對不起,應該指定:) – Lucas

0

我敢肯定這是另一個家庭作業爲類似的「劊子手」的問題已經被問喜歡4/5倍在過去的2個weeks.You有幾個錯誤:

1)您沒有分配任何值到generated_word,因此當您嘗試運行for-loop時會發生錯誤。您應該製作隨機單詞列表,然後隨機訪問它們並將其分配到generated_words

2)while循環內的第二個打印語句拼錯了。