博客
关于我
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实现奇偶转置排序算法(附完整源码)
    查看>>
    Objective-C实现奇异值分解SVD(附完整源码)
    查看>>
    Objective-C实现奎因-麦克拉斯基算法(附完整源码)
    查看>>
    Objective-C实现子集总和算法(附完整源码)
    查看>>
    Objective-C实现子集数的总和等于给定的数算法(附完整源码)
    查看>>
    Objective-C实现字符串autocomplete using trie(使用 trie 自动完成)算法(附完整源码)
    查看>>
    Objective-C实现字符串boyer moore search博耶摩尔搜索算法(附完整源码)
    查看>>
    Objective-C实现字符串IP地址转DWORD地址(附完整源码)
    查看>>
    Objective-C实现字符串jaro winkler算法(附完整源码)
    查看>>
    Objective-C实现字符串levenshtein distance编辑距离算法(附完整源码)
    查看>>
    Objective-C实现字符串manacher马拉车算法(附完整源码)
    查看>>
    Objective-C实现字符串split函数功能算法(附完整源码)
    查看>>
    Objective-C实现字符串wildcard pattern matching通配符模式匹配算法(附完整源码)
    查看>>
    Objective-C实现字符串word patterns单词模式算法(附完整源码)
    查看>>