' Def添加()'不工作

时间:2015-03-12 10:41:05

标签: python import function

import random

def multiply():
    num1 = random.randint(1,12)
    num2 = random.randint(1,12)
    ans = int(input("What is the answer to " + str(num1) + " x " + str(num2) + " ? "))
    correct = (ans == num1 * num2)
    if correct:
        print("You are correct! ")
    else:
        print("Wrong, please try again. ")
    return correct

def addition():
    num1 = random.randint(1,12)
    num2 = random.randint(1,12)
    ans = int(input("What is the answer to " + str(num1) + " + " + str(num2) + " ? "))
    correct = (ans == num1 + num2)
    if correct:
        print("You are correct! ")
    else:
        print("Wrong, please try again. ")
    return correct

name = input("What is your name? ")
maths = input("What mathematics would you like to learn, " + name + "? ")
if maths == "Multiplication" or "m" or "x":
    correct = multiply() 
elif maths == "Addition" or "a" or "x":
    correct == addition() 

我无法获得第二次“def”添加'上班。第一个“def”乘法'工作和运行正确,但' def乘以'仍然没有工作。

关于如何使这项工作的任何想法?

1 个答案:

答案 0 :(得分:2)

更改==至=因为它是作业

 correct = addition()