博客
关于我
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实现数组切片(附完整源码)
    查看>>
    Objective-C实现数组去重(附完整源码)
    查看>>
    Objective-C实现数组循环右移三次(附完整源码)
    查看>>
    Objective-C实现数组的循环右移(附完整源码)
    查看>>
    Objective-C实现数组的循环左移(附完整源码)
    查看>>
    Objective-C实现数除以二divideByTwo算法(附完整源码)
    查看>>
    Objective-C实现整个字符串转换为小写字母算法(附完整源码)
    查看>>
    Objective-C实现整数N以内的质数算法(附完整源码)
    查看>>
    Objective-C实现文件传输(附完整源码)
    查看>>
    Objective-C实现文件分割(附完整源码)
    查看>>
    Objective-C实现文件拷贝(附完整源码)
    查看>>
    Objective-C实现文件断点传输(附完整源码)
    查看>>
    Objective-C实现文件的删除、复制与重命名操作实例(附完整源码)
    查看>>
    Objective-C实现无序表查找算法(附完整源码)
    查看>>
    Objective-C实现无锁链表(附完整源码)
    查看>>
    Objective-C实现无锁链表(附完整源码)
    查看>>
    Objective-C实现时间戳转为年月日时分秒(附完整源码)
    查看>>
    Objective-C实现是否为 Pythagoreantriplet 毕氏三元数组算法(附完整源码)
    查看>>
    Objective-C实现显示响应算法(附完整源码)
    查看>>