博客
关于我
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实现列主元Gauss消去法(附完整源码)
    查看>>
    Objective-C实现列主元高斯消去法(附完整源码)
    查看>>
    Objective-C实现创建一个链表和打印该链表算法(附完整源码)
    查看>>
    Objective-C实现创建多级目录(附完整源码)
    查看>>
    Objective-C实现删除文件中的指定内容(附完整源码)
    查看>>
    Objective-C实现删除文本文件空行(附完整源码)
    查看>>
    Objective-C实现删除重复的字母字符算法(附完整源码)
    查看>>
    Objective-C实现判断32位的数字是否为正数isPositive算法(附完整源码)
    查看>>
    Objective-C实现判断A数组是否为B数组的子集(附完整源码)
    查看>>
    Objective-C实现判断IP4地址是否有效算法(附完整源码)
    查看>>
    Objective-C实现判断一个数是否为krishnamurthy数的算法(附完整源码)
    查看>>
    Objective-C实现判断一个数是否为质数算法(附完整源码)
    查看>>
    Objective-C实现判断三角形的类型(附完整源码)
    查看>>
    Objective-C实现判断位是不是偶数isEven算法(附完整源码)
    查看>>
    Objective-C实现判断字符串是否包含特殊字符算法(附完整源码)
    查看>>
    Objective-C实现判断字符串是否回文palindrome算法(附完整源码)
    查看>>
    Objective-C实现判断数是否为质数(附完整源码)
    查看>>
    Objective-C实现判断整数是否为2的幂isPowerOfTwo算法(附完整源码)
    查看>>
    Objective-C实现判断是否为回文字符串(附完整源码)
    查看>>
    Objective-C实现判断是否为回文数算法(附完整源码)
    查看>>