0

I keep getting an error in this rudimentary calculator program in Python version 3.3.1. I cannot find the problem myself, can someone help me? Thank you very much in advance!

    x=(input("Which operation would you like to perform?"))
        if x=='Addition':
        y=int(input("Enter the first number?"))
        z=int(input("Enter the second number?"))
        a=y+z
        print(a)
    elif x=='Subtraction':
        y=int(input("Enter the first number?"))
        z=int(input("Enter the second number?"))
        a=y-z
        print(a)
    elif x=='Multiplication':
        y=int(input("Enter the first number?"))
        z=int(input("Enter the second number?"))
        a=y*z
        print(a)
elif x=='Division':
        y=int(input("Enter the first number?"))
        z=int(input("Enter the second number?"))
        a=y/z
        print(a)
4

2 回答 2

0

我认为您的标签搞砸了,请尝试以下操作:

x=input("Which operation would you like to perform?")
if x=='Addition':
    y=int(input("Enter the first number?"))
    z=int(input("Enter the second number?"))
    a=y+z
    print(a)
elif x=='Subtraction':
    y=int(input("Enter the first number?"))
    z=int(input("Enter the second number?"))
    a=y-z
    print(a)
elif x=='Multiplication':
    y=int(input("Enter the first number?"))
    z=int(input("Enter the second number?"))
    a=y*z
    print(a)
elif x=='Division':
    y=int(input("Enter the first number?"))
    z=int(input("Enter the second number?"))
    a=y/z
    print(a)
于 2013-05-19T17:01:26.247 回答
-1

x= raw_input("Which operation would you like to perform?")会解决你的问题

编辑:在 python 3 raw_input 重命名为 input() 以获取旧行为使用eval(input(....)) 参考http://docs.python.org/3.0/whatsnew/3.0.html#builtins

希望这可以帮助

于 2013-05-19T17:06:18.917 回答