2017-03-31 42 views
-1

我正在創建一個數學測驗來幫助我開始使用Python,因爲我對語言非常陌生,並且它提出的unindent不匹配任何外部縮進級別錯誤消息?有人能告訴我這是什麼意思,我的錯誤在哪裏。unindent與我的數學遊戲中的任何外部縮進級別不匹配

這裏是我的代碼:

import random 

questions = 0 
correct = 0 

print ("Welcome to the maths challenge") 
print ("Out of these 10 questions how many can you get right?") 

while True : 
questions += 1 
numberA = random.randint(0,12) 
question = "What is {0}**2".format(numberA) 

print(question) 

response = input("Your Answer : ") 

answer = numberA**2 

if(int(response) == answer) : 
    print("Correct!") 

else : 
    print("Wrong!") 


if(questions == 10) : 
    print("You got {0}/{1} questions correct.").format(correct, questions) 

if correct == ("5>") 
    print ("Better luck next time") 

if correct == ("5<") 
    print ("You got a great score Well done!") 
    break 
+0

錯誤在該行。 –

回答

0

看起來正在生成該錯誤可能開始從區域:

if(questions == 10) : 

至少從你放什麼在你的問題。使用python,空格和縮進規定了大部分語言語法,而不是打開和關閉塊。因此,爲了保持縮進一致,請務必注意在塊之前使用了多少個空格或製表符。

一些IDE將極大地幫助完成此任務,例如PyCharm。其他文本編輯器(如Notepad ++)允許您搜索文本並用空格替換製表符,但這可能會超出您提出的要求。

0
if(questions == 10) : 

和所有連續線比他們的前輩縮進1個空格更遠。單空格縮進與先前的塊不匹配(縮進的零空格)。

相關問題