博客
关于我
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/

    你可能感兴趣的文章
    python mqtt 客户端实现
    查看>>
    Python Multiprocessing - 将类方法应用于对象列表
    查看>>
    Python multiprocessing.Queue 与 multiprocessing.manager().Queue()
    查看>>
    Python multiprocessing使用详解
    查看>>
    python mysql 基于 sqlalvhrmy_Python操作MySQL:pymysql和SQLAlchemy
    查看>>
    python mysql 布尔类型_python语言的基础学习:基本类型,函数,面向对象,模块,mysql数据库...
    查看>>
    Python NLP完整项目实战教程(1)
    查看>>
    Python NLP自然语言处理详解
    查看>>
    python nltk nltk_data 离线安装,chatterbot
    查看>>
    Redis 限流的 3 种方式,还有谁不会?
    查看>>
    Python这么慢,为啥大公司还在用?
    查看>>
    python note 06 编码方式
    查看>>
    python numba 转灰度图_使用NumPy、Numba的简单使用(二)
    查看>>
    Python Numpy 关于 linspace()函数 使用详解(全)
    查看>>
    Python numpy插入、读取至postgreSQL数据库中bytea类型字段
    查看>>
    Python numpy数据的保存和读取
    查看>>
    python numpy矩阵索引_python – 在2D numpy ndarray或numpy矩阵中获取前N个值的索引
    查看>>
    Python OCR库:自动化测试验证码识别神器!
    查看>>
    python opencv - 斑点检测或圆形检测
    查看>>
    Python还可以做情感分析你不看看吗?
    查看>>