博客
关于我
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实现SizeBalancedTree大小平衡树(附完整源码)
    查看>>
    Objective-C实现skew heap倾斜堆算法(附完整源码)
    查看>>
    Objective-C实现Skip List跳表算法(附完整源码)
    查看>>
    Objective-C实现slack message松弛消息算法(附完整源码)
    查看>>
    Objective-C实现SlopeOne算法(附完整源码)
    查看>>
    Objective-C实现slow sort慢排序算法(附完整源码)
    查看>>
    Objective-C实现tanh函数功能(附完整源码)
    查看>>
    Objective-C实现z-algorithm算法(附完整源码)
    查看>>
    Objective-C实现Zeller 的同余算法 (附完整源码)
    查看>>
    Objective-C实现zellers congruence泽勒一致算法(附完整源码)
    查看>>
    Objective-C实现Zero One Knapsack零一背包计算算法(附完整源码)
    查看>>
    Objective-C实现一个Pangram字符串至少包含一次所有字母算法(附完整源码)
    查看>>
    Objective-C实现一个通用的堆算法(附完整源码)
    查看>>
    Objective-C实现一分钟倒计时(附完整源码)
    查看>>
    Objective-C实现三次样条曲线(附完整源码)
    查看>>
    Objective-C实现上传文件到FTP服务器(附完整源码)
    查看>>
    Objective-C实现两个队列实现栈算法(附完整源码)
    查看>>
    Objective-C实现两数之和问题(附完整源码)
    查看>>
    Objective-C实现中值滤波(附完整源码)
    查看>>
    Objective-C实现中文模糊查询(附完整源码)
    查看>>