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

    你可能感兴趣的文章
    PyQt5——软件密码登陆跳转主界面
    查看>>
    PyQt5——通过信号与槽进行数据传输
    查看>>
    PyQt5“定时器不能从另一个线程启动“更改 QLabel 的大小时出错
    查看>>
    pyqt5不显示窗口
    查看>>
    pyqt5任意组件的拖拽问题
    查看>>
    SpringBoot中集成MobileIMSDK并实现记录所有用户以实现消息群发
    查看>>
    PyQt5信号与槽学习笔记——自定义信号与槽(二)
    查看>>
    PyQt5学习笔记——信号与槽
    查看>>
    PyQt5开发暗黑风格的计时器
    查看>>
    pyqt5教程11:绘制外观
    查看>>
    pyqt5教程12:拖放功能
    查看>>
    pyqt5教程13:客户定制组件
    查看>>
    pyqt5教程6:信号和事件
    查看>>
    PyQt5教程7:布局Layout管理
    查看>>
    pyqt5教程8:对话框
    查看>>
    pyqt5教程9:Widgets组件
    查看>>
    PyQt5教程——组件(7)
    查看>>
    pyqt5计时器的使用
    查看>>
    PyQt5设计桌面程序步骤
    查看>>
    PyQt5:检查鼠标是否在Enter-Event中按住
    查看>>