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

    你可能感兴趣的文章
    PIP使用SSH从BitBucket安装自定义软件包,无需输入SSH密码
    查看>>
    pip命令提示unknow or unsupported command install解决方法
    查看>>
    pip在安装模块时提示Read timed out
    查看>>
    pip更换源
    查看>>
    SpringBoot之Banner源码深度分解
    查看>>
    Pix2Pix如何工作?
    查看>>
    QuickBI助你成为分析师——搞定数据源
    查看>>
    pkl来存储python字典
    查看>>
    quick sort | 快速排序 C++ 实现
    查看>>
    pkpmbs 建设工程质量监督系统 Ajax_operaFile.aspx 文件读取漏洞复现
    查看>>
    pkpmbs 建设工程质量监督系统 文件上传漏洞复现
    查看>>
    pku 2400 Supervisor, Supervisee KM求最小权匹配+DFS回溯解集
    查看>>
    queue队列、deque双端队列和priority_queue优先队列
    查看>>
    PKUSC2018游记
    查看>>
    PK项目测试,做产品测试有这4大优势!
    查看>>
    pl sql 的目录 所在的目录 不能有 小括号,如 Program Files (x86)
    查看>>
    PL SQLDEVELOPMENT导出数据库脚本
    查看>>
    Queue
    查看>>
    PL/SQL Developer中文版下载以及使用图解(绿色版)
    查看>>
    pl/sql developer乱码,日期格式等问题解决
    查看>>