博客
关于我
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实现关系矩阵A和B的乘积(附完整源码)
    查看>>
    Objective-C实现内存映射文件(附完整源码)
    查看>>
    Objective-C实现内存泄露检查(附完整源码)
    查看>>
    Objective-C实现内格尔·施雷肯伯格算法(附完整源码)
    查看>>
    Objective-C实现分块查找算法(附完整源码)
    查看>>
    Objective-C实现分水岭算法(附完整源码)
    查看>>
    Objective-C实现分解质因数(附完整源码)
    查看>>
    Objective-C实现切换数字的符号switchSign算法(附完整源码)
    查看>>
    Objective-C实现列主元高斯消去法(附完整源码)
    查看>>
    Objective-C实现创建多级目录(附完整源码)
    查看>>
    Objective-C实现删除重复的字母字符算法(附完整源码)
    查看>>
    Objective-C实现判断32位的数字是否为正数isPositive算法(附完整源码)
    查看>>
    Objective-C实现十进制转N进制算法(附完整源码)
    查看>>
    Objective-C实现十进制转八进制算法(附完整源码)
    查看>>
    Objective-C实现华氏温度转摄氏温度(附完整源码)
    查看>>
    Objective-C实现单例模式(附完整源码)
    查看>>
    Objective-C实现单向链表的反转(附完整源码)
    查看>>
    Objective-C实现单向链表的反转(附完整源码)
    查看>>