2016-07-23 63 views
-4

我正在編寫python中的測驗。一切似乎工作,直到我嘗試輸入答案。我對此很新。也可以有人解釋縮進塊是什麼和它的一個例子。 這是代碼:我想用python編碼測驗,但它不工作

>>> print('physics quiz') 
physics quiz 
>>> print('round 1') 
round 1 
>>> print('what is the 1st stage of a stars life?') 
what is the 1st stage of a stars life? 
>>> print('a...protostar') 
a...protostar 
>>> print('b...nebula') 
b...nebula 
>>> print('c...red giant') 
c...red giant 
>>>answer=int(input('you have 5 seconds')) 
you have 5 seconds 
'a' 
if answer=='a': 
    print('correct') 
else: 
    print('incorrect, it was protostar') 
+0

爲了正確地格式化你的代碼,你必須在它之前和之後放置一個換行符,並在你的代碼的每一行縮進另外的4個空格。 – jotasi

+0

歡迎來到Stack Overflow。最好發佈代碼,以便我們可以快速查看哪些錯誤存在,以及可能的解決方案是否可行。有關更多信息,請參閱此處:http://stackoverflow.com/help/mcve – Toby

回答

0

在這一行

answer=int(input('you have 5 seconds')) 

你輸入轉換成int,因此它一旦失敗,INT()不能轉換輸入

0

您正在嘗試從用戶那裏獲得輸入並將其更改爲此行中的整數:

answer=int(input('you have 5 seconds'))

但是,整數只能是一個沒有句點的數字(如果那還不清楚),Python不知道該怎麼做。它會給你一個錯誤。將此行更改爲:

answer=input('you have 5 seconds')

,它會所有的工作。

相關問題