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

    你可能感兴趣的文章
    OpenCV图像的深浅拷贝
    查看>>
    OpenCV在Google Colboratory中不起作用
    查看>>
    OpenCV学习(13) 细化算法(1)(转)
    查看>>
    OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波
    查看>>
    OpenCV学堂 | CV开发者必须懂的9种距离度量方法,内含欧氏距离、切比雪夫距离等(建议收藏)
    查看>>
    OpenCV学堂 | OpenCV中支持的人脸检测方法整理与汇总
    查看>>
    OpenCV学堂 | OpenCV案例 | 基于轮廓分析对象提取
    查看>>
    OpenCV学堂 | YOLOv8与YOLO11自定义数据集迁移学习效果对比
    查看>>
    OpenCV学堂 | YOLOv8官方团队宣布YOLOv11 发布了
    查看>>
    OpenCV学堂 | YOLOv8实战 | 荧光显微镜细胞图像检测
    查看>>
    OpenCV学堂 | 汇总 | 深度学习图像去模糊技术与模型
    查看>>
    OpenCV安装
    查看>>
    OpenCV官方文档 理解k - means聚类
    查看>>
    opencv实现多路播放
    查看>>
    opencv常用函数
    查看>>
    OpenCV探索
    查看>>
    OpenCV添加中文(五)
    查看>>
    opencv源码查看
    查看>>