如何运用Python编写简易计算器
展开全部
import time
print("计算器")
print("+等于加法模式 -等于减法模式 *等于乘法模式 /等于除法模式")
while 2 > 1:
try:
print("请输入+,-,*或/")
a = input()
if a == "+":
print("请输入第1个加数")
b = input()
print("请输入第2个加数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) + float(c)
print("等于"+str(j))
elif a == "-":
print("请输入被减数")
b = input()
print("请输入减数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) - float(c)
print("等于"+str(j))
elif a == "*":
print("请输入第1个因数")
b = input()
print("请输入第2个因数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) * float(c)
print("等于"+str(j))
elif a == "/":
print("……等于余数模式 .等于小数模式")
print("请输入……或.")
a = input()
if a == ".":
print("请输入被除数")
b = input()
print("请输入除数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) / float(c)
print("等于"+str(j))
if c == "0":
print("除数不能为0!")
elif a == "……":
print("请输入被除数")
b = input()
print("请输入除数")
c = input()
j = float(b) // float(c)
e = float(b) % float(c)
print("等于"+str(j)+"……"+str(e))
if c == "0":
print("除数不能为0!")
except Exception as e:
print("您输入的内容有错误")
print("计算器")
print("+等于加法模式 -等于减法模式 *等于乘法模式 /等于除法模式")
while 2 > 1:
try:
print("请输入+,-,*或/")
a = input()
if a == "+":
print("请输入第1个加数")
b = input()
print("请输入第2个加数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) + float(c)
print("等于"+str(j))
elif a == "-":
print("请输入被减数")
b = input()
print("请输入减数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) - float(c)
print("等于"+str(j))
elif a == "*":
print("请输入第1个因数")
b = input()
print("请输入第2个因数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) * float(c)
print("等于"+str(j))
elif a == "/":
print("……等于余数模式 .等于小数模式")
print("请输入……或.")
a = input()
if a == ".":
print("请输入被除数")
b = input()
print("请输入除数")
c = input()
print("计算中")
time.sleep(0.3)
j = float(b) / float(c)
print("等于"+str(j))
if c == "0":
print("除数不能为0!")
elif a == "……":
print("请输入被除数")
b = input()
print("请输入除数")
c = input()
j = float(b) // float(c)
e = float(b) % float(c)
print("等于"+str(j)+"……"+str(e))
if c == "0":
print("除数不能为0!")
except Exception as e:
print("您输入的内容有错误")
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
2018-07-11 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
#!/usr/bin/env python# -*- coding:utf-8 -*-# @Time : 2018/1/22 22:29# @Author : zhouyuyao# @File : daemonCalculator.py# PyCharm 2017.3.2 (Community Edition)# Build #PC-173.4127.16, built on December 19, 2017# JRE: 1.8.0_152-release-1024-b8 amd64# JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o# Windows 10 10.0# Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) # [MSC v.1900 64 bit (AMD64)] on win32def add(string):
total = 0
numbers = []
numbers += string.split("+") for num in numbers:
total += int(num)
print("{0}={1}".format(string,total))def reduce(string):
result = 0
numbers = []
numbers += string.split("-")
result = int(numbers[0])
numbers.pop(0) for num in numbers:
result -= int(num)
print("{0}={1}".format(string,result))def ride(string): # 乘
total = 1
numbers = []
numbers += string.split("*") for num in numbers:
total *= int(num.strip())
print("{0}={1}".format(string,total))def division(string):
result = 0
numbers = []
numbers += string.split("/")
result = int(numbers[0])
numbers.pop(0) for num in numbers:
result /= int(num.strip())
print("{0}={1}".format(string,result))if __name__ =="__main__":
print("###############################")
print("#####欢迎来到计算器工作中心######")
print("###############################")
print("1:加法 (a+b+c+d···)")
print("2:减法 (a-b-c-d···)")
print("3:乘法 (a*b*c*d···)")
print("4:除法 (a/b/c/d···)")
method = input("Please input number(1/2/3/4): ") if method == "1": string = input("请输入您的表达式:") add(string)
elif method == "2": string = input("请输入您的表达式:")
reduce(string)
elif method == "3": string = input("请输入您的表达式:")
ride(string)
elif method == "4": string = input("请输入您的表达式:")
division(string) else:
print("The string you input is error.")
total = 0
numbers = []
numbers += string.split("+") for num in numbers:
total += int(num)
print("{0}={1}".format(string,total))def reduce(string):
result = 0
numbers = []
numbers += string.split("-")
result = int(numbers[0])
numbers.pop(0) for num in numbers:
result -= int(num)
print("{0}={1}".format(string,result))def ride(string): # 乘
total = 1
numbers = []
numbers += string.split("*") for num in numbers:
total *= int(num.strip())
print("{0}={1}".format(string,total))def division(string):
result = 0
numbers = []
numbers += string.split("/")
result = int(numbers[0])
numbers.pop(0) for num in numbers:
result /= int(num.strip())
print("{0}={1}".format(string,result))if __name__ =="__main__":
print("###############################")
print("#####欢迎来到计算器工作中心######")
print("###############################")
print("1:加法 (a+b+c+d···)")
print("2:减法 (a-b-c-d···)")
print("3:乘法 (a*b*c*d···)")
print("4:除法 (a/b/c/d···)")
method = input("Please input number(1/2/3/4): ") if method == "1": string = input("请输入您的表达式:") add(string)
elif method == "2": string = input("请输入您的表达式:")
reduce(string)
elif method == "3": string = input("请输入您的表达式:")
ride(string)
elif method == "4": string = input("请输入您的表达式:")
division(string) else:
print("The string you input is error.")
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询