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

    你可能感兴趣的文章
    OpenGL/OpenGL ES 入门:基础变换 - 初识向量/矩阵
    查看>>
    OpenGL中shader读取实现
    查看>>
    OpenGL中旋转平移缩放等变换的顺序对模型的影响
    查看>>
    Opengl中的gluProject函数认识
    查看>>
    OpenGl介绍
    查看>>
    OPENGL半透明图像产生黑色光环
    查看>>
    OpenGL和图形卡
    查看>>
    OpenGL字体绘制
    查看>>
    OpenGL学习
    查看>>
    openGL学习步骤
    查看>>
    OpenGL的基本概念介绍
    查看>>
    OpenGL着色器、纹理开发案例
    查看>>
    OpenGL程序无法启动此应用程序,因为计算机中丢失glut32.dll(转))
    查看>>
    opengl绘制几何体的函数
    查看>>
    openGL缓存概念和缓存清除(01)
    查看>>
    OpenJDK11 下的HSDB工具使用入门
    查看>>
    openjdk踩坑
    查看>>
    openjudge 1792 迷宫 解析报告
    查看>>
    OpenJudge/Poj 1658 Eva's Problem
    查看>>
    Openlayers 9.0新功能
    查看>>