鱼C论坛

 找回密码
 立即注册
查看: 3307|回复: 1

[学习笔记] Python超级超级简易计算器---decorator装饰器写法

[复制链接]
发表于 2020-8-22 17:12:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. print("Python简易计算器--decorator")
  2. circle=input("请输入一个四则运算式:")
  3. def all(function):
  4.     def get():
  5.         function()
  6.     return get
  7. @all
  8. def start():
  9.     if circle.partition("+")[0]!=circle:
  10.         infront=circle.partition("+")[0]
  11.         behind=circle.partition("+")[2]
  12.         print(infront,"+",behind,"=",str(float(infront)+float(behind)))
  13.     elif circle.partition("*")[0]!=circle:
  14.         infront=circle.partition("*")[0]
  15.         behind=circle.partition("*")[2]
  16.         print(infront,"*",behind,"=",str(float(infront)*float(behind)))
  17.     elif circle.partition("-")[0]!=circle:
  18.         infront=circle.partition("-")[0]
  19.         behind=circle.partition("-")[2]
  20.         print(infront,"-",behind,"=",str(float(infront)-float(behind)))
  21.     elif circle.partition("/")[0]!=circle:
  22.         infront=circle.partition("/")[0]
  23.         behind=circle.partition("/")[2]
  24.         if behind=="0":
  25.             print("除数不能为零...程序即将报错停止")
  26.             assert False
  27.         print(infront,"/",behind,"=",str(float(infront)/float(behind)))
  28. start()
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-22 17:27:49 | 显示全部楼层
厉害
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 20:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表