#return(函数运算结果的返回用 return)
print('欢迎使用计算机')
def jia(x,y):(设置函数变量x,y)
return(x+y) #(returnx+y的值)
def jian(x,y):
return(x-y)
def cheng(x,y):
return(x*y)
def chu(x,y):
return(x/y)
a=int(input('请输入第一个数字'))
while True:
b=input('请输入符号,或输入q推出')
while (b != '+' and b != '-' and b != '*' and b != '/' and b != 'q'):
print('非法输入,请正确输入如:+ - * /')
b=input('请输入符号,或输入q推出')
if b == 'q':
break(结束循环)
c=int(input('请输入第二个数字'))
if b == '+':
a = jia(a,c)
print(a)
elif b == '-':
a = jian(a,c)
print(a)
elif b == '*':
a = cheng(a,c)
print(a)
else:
a= chu(a,c)
print(a)
网友评论