关于python计算器中的num1和num2

时间:2015-04-29 08:22:06

标签: variables python-3.x

如果没有一个变量表示num1和num2变量的值,为什么会这样? 我的意思是,没有必要将输入添加到num1和num2? 我很困惑,我在编码方面很陌生

{

#Returns the sum of num1 and num2

def add(num1, num2):
    return num1 + num2

#Returns the subtracting of num1 and num2

def sub(num1, num2):
    return num1 - num2

#Returns the multiplying of num1 and num2

def mul(num1, num2):
    return num1 * num2

#Returns the dividing of num1 and num2

def div(num1, num2):
    return num1 / num2



def main():
    operation = input("What do you want to do (+,-,*,/): ")
    if(operation != "+" and operation != "-" and operation != "*" and operation != "/"):
        #Invalid operation
        print("You must enter a valid operation")
    else:
        var1 = int(input("Enter num1: "))
        var2 = int(input("Enter num2: "))

        if(operation == "+"):
            print(add(var1, var2))

        elif(operation == "/"):
            print(div(var1, var2))

        elif(operation == "-"):
            print(sub(var1, var2))

        else:
            print(mul(var1, var2))

main()}

0 个答案:

没有答案