[英]Trying to do a math quiz in python
I am trying to make a math quiz on python, and I am trying not to use random.我正在尝试在 python 上进行数学测验,并且我试图不使用随机。 When I set user input to the answer of the problem and then try to run it, it says its wrong.
当我将用户输入设置为问题的答案然后尝试运行它时,它说它错了。 Why?
为什么? Here is apart of my code.
这是我的代码的一部分。 When I answer '78' correctly, it says sorry that is not right.
当我正确回答“78”时,它会说对不起,这是不对的。
def problem1():
raw_input('36 + 42 = ')
if input == '78':
print('Correct!')
else:
print('Sorry that is not right.')
You're calling raw_input
, but not saving its returned string, which is the user's input.您正在调用
raw_input
,但没有保存其返回的字符串,这是用户的输入。 Then you're comparing the existing input
function against "78"
which will never be correct.然后您将现有的
input
函数与永远不会正确的"78"
进行比较。
Just save the users input properly then use it in the comparison:只需正确保存用户输入,然后在比较中使用它:
inp = raw_input('36 + 42 = ')
if inp == '78':
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.