|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- print("Python简易计算器--decorator")
- circle=input("请输入一个四则运算式:")
- def all(function):
- def get():
- function()
- return get
- @all
- def start():
- if circle.partition("+")[0]!=circle:
- infront=circle.partition("+")[0]
- behind=circle.partition("+")[2]
- print(infront,"+",behind,"=",str(float(infront)+float(behind)))
- elif circle.partition("*")[0]!=circle:
- infront=circle.partition("*")[0]
- behind=circle.partition("*")[2]
- print(infront,"*",behind,"=",str(float(infront)*float(behind)))
- elif circle.partition("-")[0]!=circle:
- infront=circle.partition("-")[0]
- behind=circle.partition("-")[2]
- print(infront,"-",behind,"=",str(float(infront)-float(behind)))
- elif circle.partition("/")[0]!=circle:
- infront=circle.partition("/")[0]
- behind=circle.partition("/")[2]
- if behind=="0":
- print("除数不能为零...程序即将报错停止")
- assert False
- print(infront,"/",behind,"=",str(float(infront)/float(behind)))
- start()
复制代码 |
|