博客
关于我
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实现FTP文件下载(附完整源码)
    查看>>
    Objective-C实现fuzzy operations模糊运算算法(附完整源码)
    查看>>
    Objective-C实现Gale-Shapley盖尔-沙普利算法(附完整源码)
    查看>>
    Objective-C实现gamma recursive伽玛递归算法(附完整源码)
    查看>>
    Objective-C实现gamma 伽玛功能算法(附完整源码)
    查看>>
    Objective-C实现gauss easte高斯复活节日期算法(附完整源码)
    查看>>
    Objective-C实现gaussian filter高斯滤波器算法(附完整源码)
    查看>>
    Objective-C实现gaussian naive bayes高斯贝叶斯算法(附完整源码)
    查看>>
    Objective-C实现gaussian高斯算法(附完整源码)
    查看>>
    Objective-C实现geometric series几何系列算法(附完整源码)
    查看>>
    Objective-C实现getline函数功能(附完整源码)
    查看>>
    Objective-C实现gnome sortt侏儒排序算法(附完整源码)
    查看>>
    Objective-C实现graph list图列算法(附完整源码)
    查看>>
    Objective-C实现GraphEdge图边算法(附完整源码)
    查看>>
    Objective-C实现GraphVertex图顶点算法(附完整源码)
    查看>>
    Objective-C实现greatest common divisor最大公约数算法(附完整源码)
    查看>>
    Objective-C实现greedy coin change贪心硬币找零算法(附完整源码)
    查看>>