【发布时间】:2014-09-17 17:20:37
【问题描述】:
我有这个代码:
while no_questions < 10:
# Creating question and random values
question = "" # Blanking the question for continues use of one variable
num1 = randint(1, 10); num2 = randint(1, 10); op = choice(operators)
question = op(num1, num2)
real_answer = question
# Change operator to string for use in format for later output
if op == add:
op = "plus"
elif op == sub:
op = "minus"
elif op == mul:
op = "times"
answer = raw_input("What is {0} {1} {2}?".format(num1, op, num2))
# Checking answer and updating score
if answer == question:
print "Well done {0}! You got that right!".format(usr_name)
score += 1
else:
pass
no_questions += 1
这是我在学校做的一个项目的一部分。但是,当我通过此循环时,最后一个 if 语句将返回 True,无论输入是什么。我的代码是错误的还是我没有遇到过的python 法?非常感谢。
【问题讨论】:
-
查看 if 语句中的两个值并查看它们最初设置的位置。
-
@MatthewC,您已编辑问题以删除三个答案提供的错误。为什么?
标签: python if-statement return