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

    你可能感兴趣的文章
    php 阿里云oss 上传回调
    查看>>
    PHP 面向对象 final类与final方法
    查看>>
    php+JQ+EasyUI自动加载数据
    查看>>
    php+sql server根据自增序号id区间查询第几条到第几条的数据
    查看>>
    php--------获取当前时间、时间戳
    查看>>
    Redis使用场景举例
    查看>>
    php--正则表达式
    查看>>
    php--防止sql注入的方法
    查看>>
    PHP-CGI Windows平台远程代码执行漏洞复现(CVE-2024-4577)
    查看>>
    php-cgi耗尽报502错误
    查看>>
    php-cgi(fpm-cgi) 进程 CPU 100% 与 file_get_content...
    查看>>
    PHP-DI/Invoker 开源项目使用教程
    查看>>
    php-fpm与Nginx运行常见错误说明
    查看>>
    php-fpm比php成为apache模块好在哪
    查看>>
    php-fpm超时时间设置request_terminate_timeout分析
    查看>>
    php-fpm进程数优化
    查看>>
    PHP-GD库-分类整理
    查看>>
    php-laravel框架用户验证(Auth)模块解析(一)
    查看>>
    php-laravel框架用户验证(Auth)模块解析(三)登录模块
    查看>>
    php-laravel框架用户验证(Auth)模块解析(二)注册模块
    查看>>