博客
关于我
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实现number of digits解字符数算法(附完整源码)
    查看>>
    Objective-C实现NumberOfIslands岛屿的个数算法(附完整源码)
    查看>>
    Objective-C实现numerical integration数值积分算法(附完整源码)
    查看>>
    Objective-C实现n个取m个数的组合算法(附完整源码)
    查看>>
    Objective-C实现N数理论(质素相关)算法(附完整源码)
    查看>>
    Objective-C实现n皇后问题算法(附完整源码)
    查看>>
    Objective-C实现O(E + V) 中找到 0-1-graph 中的最短路径算法(附完整源码)
    查看>>
    Objective-C实现OCR文字识别(附完整源码)
    查看>>
    Objective-C实现odd even sort奇偶排序算法(附完整源码)
    查看>>
    Objective-C实现ohms law欧姆定律算法(附完整源码)
    查看>>
    Objective-C实现P-Series algorithm算法(附完整源码)
    查看>>
    Objective-C实现page rank算法(附完整源码)
    查看>>
    Objective-C实现PageRank算法(附完整源码)
    查看>>
    Objective-C实现pancake sort煎饼排序算法(附完整源码)
    查看>>
    Objective-C实现pascalTriangle帕斯卡三角形算法(附完整源码)
    查看>>
    Objective-C实现PascalTriangle帕斯卡三角算法 (附完整源码)
    查看>>
    Objective-C实现password generator复杂密码生成器算法(附完整源码)
    查看>>
    Objective-C实现patience sort耐心排序算法(附完整源码)
    查看>>
    Objective-C实现PCA(附完整源码)
    查看>>
    Objective-C实现perceptron算法(附完整源码)
    查看>>