博客
关于我
Python多分支实现四则运算器
阅读量:63 次
发布时间:2019-02-26

本文共 1300 字,大约阅读时间需要 4 分钟。

???????????

?????????????????????????????????????????????????????????????????????????????????????

????

  • ????

    • ??????????????????
    • ???????????????????????????????
    • ???????????????????????????????
  • ????

    • ??????????????????????Error???????
    • ??try-except?????????????????????
  • ????

    • ????????????????????
    • ??????????????round???????????
  • ??????

    class Calculator:    def __init__(self, a, b):        self.a = a        self.b = b    def addition(self, retain):        return round(self.a + self.b, retain)    def subtraction(self, retain):        return round(self.a - self.b, retain)    def multiplication(self, retain):        return round(self.a * self.b, retain)    def division(self, retain):        return round(self.a / self.b, retain)while True:    try:        num1 = float(input('???????:'))        num2 = float(input('???????:'))        operator = input('??????:')        retain = int(input('?????????:'))    except ValueError:        print("Error")        break    if operator not in ['+', '-', '*', '/']:        print("Error")        break    result = Calculator(num1, num2).{        '+' if operator == '+' else        '-' if operator == '-' else        '*' if operator == '*' else        '/' if operator == '/' else    }(retain)    print(result)

    ????

    • ?????????????????????????
    • ?????????????Error??????????

    转载地址:http://cpr.baihongyu.com/

    你可能感兴趣的文章
    ospf综合实验2 2012/9/8
    查看>>
    OSPF规划两大模型:双塔奇兵、犬牙交错
    查看>>
    OSPF认证
    查看>>
    OSPF设计原则,命令以H3C为例
    查看>>
    ospf路由 华3_动态路由OSPF基本原理及配置,一分钟了解下
    查看>>
    OSPF路由协议配置
    查看>>
    OSPRay 开源项目教程
    查看>>
    VC++实现应用程序对插件的支持
    查看>>
    OSS 访问图片资源报“No ‘Access-Control-Allow-Origin‘”的错误
    查看>>
    ossfs常见配置错误
    查看>>
    Ossim4系统故障处理
    查看>>
    Spring赌上未来:响应式的 WebFlux 框架更优雅,性能更强!
    查看>>
    oss报UnknownHost,k8s设置hostAliases参数
    查看>>
    OSS报错The difference between the request time and the current time is too large
    查看>>
    OSS直传与UXCore-Uploader实践
    查看>>
    Spring详解Bean的生命周期
    查看>>
    OS模块
    查看>>
    OS第1章
    查看>>
    OS第2章 —— 进程
    查看>>
    OS第3章 —— 进程调度和死锁
    查看>>