博客
关于我
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学习(13) 细化算法(1)(转)
    查看>>
    OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波
    查看>>
    OpenCV学堂 | OpenCV案例 | 基于轮廓分析对象提取
    查看>>
    OpenCV学堂 | YOLOv8实战 | 荧光显微镜细胞图像检测
    查看>>
    OpenCV官方文档 理解k - means聚类
    查看>>
    OpenCV探索
    查看>>
    OpenCV环境搭建(一)
    查看>>
    openCV目标识别 目标跟踪 YOLO5深度学习 Python 计算机视觉 计算机毕业设计 源码下载
    查看>>
    opencv笔记(1):图像缩放
    查看>>
    opencv笔记(二十四)——得到轮廓之后找到凸包convex hull
    查看>>
    OpenCV计算点到直线的距离 数学法
    查看>>
    Opencv识别图中人脸
    查看>>
    OpenCV读写avi、mpeg文件
    查看>>
    opencv面向对象设计初探
    查看>>
    OpenCV(1)读写图像
    查看>>
    OpenCV:不规则形状区域中每种颜色的像素数?
    查看>>
    OpenCV:概念、历史、应用场景示例、核心模块、安装配置
    查看>>
    OpenDaylight融合OpenStack架构分析
    查看>>
    openEuler Summit 2022 成功举行,开启全场景创新新时代
    查看>>
    openEuler 正式开放:推动计算多样化时代的到来
    查看>>