1 个回答
提问:pythonelif错误
a=int(input()) #第1个数字b=int(input()) #第2个数字print("请输入运算符号")x=input() if x==r("+"): #运算符号 def jieguo(o,p): c=o+p return c elif x==r("-"): #这里的elif错误了 def jieguo(o,p): c=o-p return c elif x==r("*"): def jieguo(o,p): c=o*p return c elif x==r("/"): def jieguo(o,p): c=o//p return c else: def jieguo(o,p): c=o**p return cm=jieguo(a,b) #结果print(m)
网友回答:
python是靠缩进来区分程序块的,你上传的程序缩进完全不对
另外,r后面不能有()的(它识别为函数了)
以下是改好,可以运行的
a=int(input()) #第1个数字
b=int(input()) #第2个数字
print("请输入运算符号")
x=input()
if x==r"+": #运算符号
def jieguo(o,p):
c=o+p
return c
elif x==r"-": #这里的elif错误了
def jieguo(o,p):
c=o-p
return c
elif x==r"*":
def jieguo(o,p):
c=o*p
return c
elif x==r"/":
def jieguo(o,p):
c=o//p
return c
else:
def jieguo(o,p):
c=o**p
return c
m=jieguo(a,b) #结果
print(m)