博客
关于我
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/

    你可能感兴趣的文章
    Objective-C实现域名解析(附完整源码)
    查看>>
    Objective-C实现域名转IP(附完整源码)
    查看>>
    Objective-C实现培根密码算法(附完整源码)
    查看>>
    Objective-C实现基于 LIFO的堆栈算法(附完整源码)
    查看>>
    Objective-C实现基于 LinkedList 的添加两个数字的解决方案算法(附完整源码)
    查看>>
    Objective-C实现基于opencv的抖动算法(附完整源码)
    查看>>
    Objective-C实现基于事件对象实现线程同步(附完整源码)
    查看>>
    Objective-C实现基于信号实现线程同步(附完整源码)
    查看>>
    Objective-C实现基于数据流拷贝文件(附完整源码)
    查看>>
    Objective-C实现基于文件流拷贝文件(附完整源码)
    查看>>
    Objective-C实现基于模板的双向链表(附完整源码)
    查看>>
    Objective-C实现基于模板的顺序表(附完整源码)
    查看>>
    Objective-C实现基本二叉树算法(附完整源码)
    查看>>
    Objective-C实现堆排序(附完整源码)
    查看>>
    Objective-C实现填充环形矩阵(附完整源码)
    查看>>
    Objective-C实现声音录制播放程序(附完整源码)
    查看>>
    Objective-C实现备忘录模式(附完整源码)
    查看>>
    Objective-C实现复制粘贴文本功能(附完整源码)
    查看>>
    Objective-C实现复数的加减乘除(附完整源码)
    查看>>
    Objective-C实现复数类+-x%(附完整源码)
    查看>>