马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一开始没效果,根据小甲鱼教程的map例子重复对了15分钟,最后自己发现要加一个*来解收集函数.....教程上没有....print("Python简易计算器--Map映射写法")
circle=input("请输入一个四则运算式子:")
if circle.find("+")!=-1:
print(circle.partition("+")[0],"+",circle.partition("+")[2],"=",*map(lambda infront,behind:infront+behind,[float(circle.partition("+")[0])],[float(circle.partition("+")[2])]))
if circle.find("-")!=-1:
print(circle.partition("-")[0],"-",circle.partition("-")[2],"=",*map(lambda infront,behind:infront-behind,[float(circle.partition("-")[0])],[float(circle.partition("-")[2])]))
if circle.find("*")!=-1:
print(circle.partition("*")[0],"*",circle.partition("*")[2],"=",*map(lambda infront,behind:infront*behind,[float(circle.partition("*")[0])],[float(circle.partition("*")[2])]))
if circle.find("/")!=-1:
if circle.partition("/")[2]=="0":
print("除数不能为零...程序即将报错停止")
assert False
print(circle.partition("/")[0],"/",circle.partition("/")[2],"=",*map(lambda infront,behind:infront/behind,[float(circle.partition("/")[0])],[float(circle.partition("/")[2])]))
|