我正在尝试使用python编写测验,但它不起作用

时间:2016-07-23 14:58:18

标签: 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')

2 个答案:

答案 0 :(得分:0)

在这一行

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

您正在将输入转换为int,因此一旦int()无法转换输入,它将失败

答案 1 :(得分:0)

您正在尝试从用户那里获取输入并将其更改为此行中的整数:

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

但是,整数只能是没有句点的数字(如果还不清楚),Python不知道该怎么做。它会给你一个错误。将此行更改为:

answer=input('you have 5 seconds')

并且一切正常。

相关问题