while True:
# 用户输入,两位数、运算符
num1 = float(input("请输入第一个数: "))
num2 = float(input("请输入第二个数: "))
operator = input("请输入运算符: ")
# 开始计算
if operator == "+":
print("%s %s %s = %s"%(num1,operator,num2,(num1 + num2)))
elif operator == "-":
print("%s %s %s = %s"%(num1,operator,num2,(num1 - num2)))
elif operator == "*":
print("%s %s %s = %s"%(num1,operator,num2,(num1 * num2)))
elif operator == "/":
print("%s %s %s = %s"%(num1,operator,num2,(num1 / num2)))
confom = input("请问需要继续吗?(Y/y)")
if confom != "y" and confom != "Y":
break
Python 实战案例--计算器
最新推荐文章于 2023-03-23 10:04:49 发布