博客
关于我
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实现SudokuSolver数独解决方案算法(附完整源码)
    查看>>
    Objective-C实现Sudoku数独游戏算法(附完整源码)
    查看>>
    Objective-C实现sum of arithmetic series算术级数之和算法(附完整源码)
    查看>>
    Objective-C实现sum of geometric progression几何级数之和算法(附完整源码)
    查看>>
    Objective-C实现sum of subset子集总和算法(附完整源码)
    查看>>
    Objective-C实现SumOfSubset子集总和为一个定值的算法(附完整源码)
    查看>>
    Objective-C实现support vector machines支持向量机算法(附完整源码)
    查看>>
    Objective-C实现SVM支持向量机算法(附完整源码)
    查看>>
    Objective-C实现SVM支持向量机(附完整源码)
    查看>>
    Objective-C实现sylvester西尔维斯特方程算法(附完整源码)
    查看>>
    Objective-C实现tabu search禁忌搜索算法(附完整源码)
    查看>>
    Objective-C实现tanh函数功能(附完整源码)
    查看>>
    Objective-C实现Tarjan 用于在有向图中查找强连通分量的算法(附完整源码)
    查看>>
    Objective-C实现TCP Server 多线程同时连接多个客户端(附完整源码)
    查看>>
    Objective-C实现TCP拥塞控制(附完整源码)
    查看>>
    Objective-C实现tcp网络通讯服务器+客户端(附完整源码)
    查看>>
    Objective-C实现temperature conversions温度转换算法(附完整源码)
    查看>>
    Objective-C实现Tenengrad梯度函数(附完整源码)
    查看>>
    Objective-C实现ternary search三元搜索算法(附完整源码)
    查看>>
    Objective-C实现TernarySearch三分查找算法(附完整源码)
    查看>>