1 def jaifa(x,y): //定义加减乘除的函数
2 return x+y //返回结果
3 def jianfa (x,y):
4 return x-y
5 def cengfa(x,y):
6 return xy
7 def chufa(x,y):
8 return x/y
9 print('欢迎来到小艾简易计算器')
10 a=int(input('shurucengshu')) //输入相应的变量
11 while(True):
12 fuHao=input('shurufuhao') //输入相应的符号
13 while(fuHao!='+' and fuHao!='-' and fuHao!='' and fuHao!='/' and fuHao!= 'q'): //判断符号
14 print('符号输入错误 请重新输入')
15 fuHao=input('shurufuhao')
16 if(fuHao=='q'):
17 break
18 b=int(input('shurubeicengshu'))
19 if(fuHao=='+'): //判断输入符号,是加减乘除中的哪一个
20 a=jaifa(a,b)
21 print(a)
22 elif(fuHao=='-'):
23 a=jianfa(a,b)
24 print(a)
25 elif(fuHao=='*'):
26 a=cengfa(a,b)
27 print(a)
28 elif(fuHao=='/'):
29 a=chufa(a,b)
30 print(a)
运行效果图如下
计算器.PNG
网友评论