编写程序:从键盘输入三个实数分别赋给x,y,z,打印三个数的加、减、乘、除的值,并理解input()函数的使用。(注意考虑输入的数不是数字的情况已经输入的数为零时两种情况的处理)
# By yangbocsu 2021.09.25
x = input("请输入数字(x):")
y = input("请输入数字(y):")
z = input("请输入数字(z):")
# 数据边界处理
if not x.isdigit() or not y.isdigit() or not z.isdigit():
print("输入的数有不是数字,无法进行四则运算")
else:
# 输入的三个都是数字
#加法 减法
x = float(x)
y = float(y)
z = float(z)
print("加法:" + str(x+y+z))
print("减法:" + str(x-y-z))
print("乘法:" + str(x*y*z))
#除法
if y == 0 or z == 0:
print("输入的后两位有0,无法进行除法运算")
else:
print("除法:" + str(x/y/z))
num=[0,1,2,3,4,5,6,7,8,9]#实数
x=float(input('x'))
while x not in num:
print('并不是数字,请重新输入。')
x=input('请重新输入x')
y=float(input('y'))
while y not in num:
print('并不是数字,请重新输入。')
y=input('请重新输入y')
z=float(input('z'))
while z not in num:
print('并不是数字,请重新输入。')
z=input('请重新输入z')
sum=x+y+z
sub=x-y-z
mul=x*y*z
print(f'{sum}\n{sub}\n{mul}')
try:
div=(x/y)/z
print(div)
except:
print('除数不能为0')