我做错了什么,我不知道如何修复我的代码

时间:2015-09-22 07:59:05

标签: python python-3.x

我正在尝试在python中进行数学测验,而当我输入正确的答案时,大多数代码都能正常工作,但代码总是打印不正确。

import random


Name=input("What is your name?")
Class=input("wWhat class are you in?")
print("Welcome" ,Name, "to the Maths Quiz!!")

QuestionNumber=0
Operations=["+","-","x"]

Num1=random.randint(1,30)
Num2=random.randint(1,30)     
answer=0

while QuestionNumber < 10:
    QuestionNumber=QuestionNumber+1
    print("What is", Num1 ,random.choice(Operations),Num2)
    guess=int(input("What is the answer to this question?"))

    if Operations=="+":
        answer=Num1+Num2

    elif Operations=="-":
            answer=Num1-Num2

    elif Operations=="x":
        answer=Num1*Num2

    if guess==answer:
        print ("Correct")

    else:
        print("Incorrect")

0 个答案:

没有答案