1 def count(temp1,cha,temp2):2 res = int(temp1) cha int(temp2)3 return res4 way = input("请输入计算方式(加/减/乘/除):")5 temp1 = input("输入第一个数")6 temp2 = input("输入第二个数")7 if way == '加':8 res = jia(temp1,+,temp2)9 elif way == '减':10 res = jian(temp1,-,temp2)11 elif way == '乘':12 res = cheng(temp1,*,temp2)13 elif way == '除':14 res = chu(temp1,/,temp2)15 print(res)下面的这个补充的和上面的是一样的,但最初提问或许系统有些问题,没有缩进————————————————————————————————————1 def count(temp1,cha,temp2):2 res = int(temp1) cha int(temp2)3 return res4 way = input("请输入计算方式(加/减/乘/除):")5 temp1 = input("输入第一个数")6 temp2 = input("输入第二个数")7 if way == '加':8 res = jia(temp1,+,temp2)9 elif way == '减':10 res = jian(temp1,-,temp2)11 elif way == '乘':12 res = cheng(temp1,*,temp2)13 elif way == '除':14 res = chu(temp1,/,temp2)15 print(res)
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
不是很明白你给的代码逻辑。你定义了一个函数,叫count,传入的是三个参数,要做的是将三个参数拼接成一个算式并返回。但是在后面的代码中出现了“jia”、“jian”、“cheng”、“chu”四个函数名,你都没定义怎么调用?
#coding:gbkdef count(temp1,cha,temp2): if isinstance(temp1,(int,float)) and isinstance(temp2,(int,float)): res = str(temp1) + cha + str(temp2) else: res = temp1 + cha + temp2 return resway = input("请输入计算式(加/减/乘/除):")temp1 = input("输入第数")temp2 = input("输入第二数") if way == '加': res = count(temp1,'+',temp2)elif way == '减': res = count(temp1,'-',temp2)elif way == '乘': res = count(temp1,'*',temp2)elif way == '除': res = count(temp1,'/',temp2)print(res) |
添加回答
举报
0/150
提交
取消
