为什么在编译单个语句错误时会找到多个语句? (蟒蛇)

时间:2013-05-19 16:56:10

标签: python

我在Python 3.3.1版本的这个基本计算器程序中一直出错。我自己找不到问题,有人能帮助我吗?非常感谢你提前!

    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)

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:-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

来获取旧行为

希望这有帮助