Python超级超级简易计算器---Lambda匿名函数写法
看小甲鱼的书看到了匿名函数,突然发现又可以写一个很简单的计算器print("Python简易计算器--Lambda匿名函数写法...")
circle=input("请输入一个四则运算式子:")
if circle.find("+")!=-1:
all=lambda infront,behind:infront+behind
print(circle.partition("+"),"+",circle.partition("+"),"=",str(all(float(circle.partition("+")),float(circle.partition("+")))))
elif circle.find("*")!=-1:
all=lambda infront,behind:infront*behind
print(circle.partition("*"),"*",circle.partition("*"),"=",str(all(float(circle.partition("*")),float(circle.partition("*")))))
elif circle.find("-")!=-1:
all=lambda infront,behind:infront-behind
print(circle.partition("-"),"-",circle.partition("-"),"=",str(all(float(circle.partition("-")),float(circle.partition("-")))))
elif circle.find("/")!=-1:
all=lambda infront,behind:infront/behind
if circle.partition("/")=="0":
print("除数不能为零...程序即将报错停止")
assert False
print(circle.partition("/"),"/",circle.partition("/"),"=",str(all(float(circle.partition("/")),float(circle.partition("/")))))
页:
[1]