Python超级超级简易计算器---decorator装饰器写法
print("Python简易计算器--decorator")circle=input("请输入一个四则运算式:")
def all(function):
def get():
function()
return get
@all
def start():
if circle.partition("+")!=circle:
infront=circle.partition("+")
behind=circle.partition("+")
print(infront,"+",behind,"=",str(float(infront)+float(behind)))
elif circle.partition("*")!=circle:
infront=circle.partition("*")
behind=circle.partition("*")
print(infront,"*",behind,"=",str(float(infront)*float(behind)))
elif circle.partition("-")!=circle:
infront=circle.partition("-")
behind=circle.partition("-")
print(infront,"-",behind,"=",str(float(infront)-float(behind)))
elif circle.partition("/")!=circle:
infront=circle.partition("/")
behind=circle.partition("/")
if behind=="0":
print("除数不能为零...程序即将报错停止")
assert False
print(infront,"/",behind,"=",str(float(infront)/float(behind)))
start() 厉害{:7_146:}
页:
[1]