Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在编译单个语句错误时发现多个语句?(Python)_Python - Fatal编程技术网

为什么在编译单个语句错误时发现多个语句?(Python)

为什么在编译单个语句错误时发现多个语句?(Python),python,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

在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)

你的标签搞乱了,我想,试试这样:

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)
x=原始输入您希望执行哪个操作?会解决你的问题

编辑:在Python3中,原始输入被重命名为input,以获得旧的行为use evalinput。。。。参考文献


希望这有帮助

您能发布错误吗?我想您只是有缩进问题。还是只是复制粘贴的结果?为什么在第一个输入调用中使用了额外的括号?尝试重新制表。这只是复制粘贴排序错误仅显示SyntaxError:编译单个语句时发现多个语句它位于第一行,x=input您希望执行哪项操作?为什么第一次输入调用中会有额外的括号?使用raw\u input会给我一个回溯回溯最近的调用最后:文件,第1行,在x=raw\u input中,您希望执行哪项操作?NameError:name“raw_input”未定义。Python 3中不存在raw_input。@user2399322我逐字复制/粘贴了这个答案中的代码块,它对我有效。@Aya您使用的是空闲的Python gui吗?您是否使用了3.3.1版?@user2399322检查您的python-V我相信您无意中使用了2.X来运行代码。@Emil上面的版本说明了python 3.3.1 v3.3.1:d9893d13c628,2013年4月6日,20:30:21[MSC V.1600 64位AMD64]在win32上@Emil我仍然得到语法错误:编译单个语句时发现多个语句