這是我編輯過的一個簡單的小猜謎遊戲。我知道應該運行良好,但它不斷給我一個錯誤。在第12行,它表示「unindent不匹配任何外部縮進級別」,箭頭指向「guess = input()」中的右括號。任何幫助?我看不出它有什麼問題!python隨機數字遊戲中的縮進錯誤
# This is a guess the number game.
import random
guessesTaken = 0
print('Hello! What is your name?')
myName = input()
number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
while guessesTaken < 6:
print('Take a guess.')
guess = input()
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
用'python -tt my_script'運行它永遠不要混合製表符和空格,並使用一個好的編輯器/ ide – 2013-04-22 17:07:16
那麼這很可能是我的問題。我別無選擇,只能使用在線IDE,它有時候會混淆我的代碼。 – Xiam 2013-04-22 17:19:57
你是什麼意思你別無選擇?如果需要,你可以在記事本中編寫python。 – thegrinner 2013-04-22 17:51:44