2417944015 发表于 2020-8-22 17:12:15

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()

xiao-wugui 发表于 2020-8-22 17:27:49

厉害{:7_146:}
页: [1]
查看完整版本: Python超级超级简易计算器---decorator装饰器写法