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

    你可能感兴趣的文章
    Nodejs简介以及Windows上安装Nodejs
    查看>>
    nodejs系列之express
    查看>>
    nodejs系列之Koa2
    查看>>
    Nodejs连接mysql
    查看>>
    nodejs连接mysql
    查看>>
    NodeJs连接Oracle数据库
    查看>>
    nodejs配置express服务器,运行自动打开浏览器
    查看>>
    NodeMCU教程 http请求获取Json中文乱码解决方案
    查看>>
    Nodemon 深入解析与使用
    查看>>
    NodeSession:高效且灵活的Node.js会话管理工具
    查看>>
    node~ http缓存
    查看>>
    node不是内部命令时配置node环境变量
    查看>>
    node中fs模块之文件操作
    查看>>
    Node中同步与异步的方式读取文件
    查看>>
    node中的get请求和post请求的不同操作【node学习第五篇】
    查看>>
    Node中的Http模块和Url模块的使用
    查看>>
    Node中自启动工具supervisor的使用
    查看>>
    Node入门之创建第一个HelloNode
    查看>>
    node全局对象 文件系统
    查看>>
    Node出错导致运行崩溃的解决方案
    查看>>