【发布时间】:2015-03-20 12:06:14
【问题描述】:
def multiply(): #starts sub program when 'multiply()' is called
num1 = random.randint(1,12) #randomly generates a number between 1 and 12
num2 = random.randint(1,12)
while loop == True: #creates loop, and uses previously defined 'loop'
ans = int(input("What is the answer to " + str(num1) + " x " + str(num2) + " ? ")) #asks question and requires a user input
correct = (ans == num1 * num2)
if correct:
print("You are correct! ")
break #if the answer is correct, it prints 'You are correct!' and breaks to avoid the loop
else:
print("Wrong, please try again. ")
loop == False #if the answer is wrong, it loops back to when 'loop' was last 'True'
我想知道是否有办法让我包含一行代码,让我显示“这不是一个选项!”当在代码的第 5 行输入除数字以外的符号时。
【问题讨论】:
-
@user5061 由于他们
print语句的语法和使用input而不是raw_input,我将假设3.x