博客
关于我
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-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)模块解析(二)注册模块
    查看>>
    php-laravel框架用户验证(Auth)模块解析(四)忘记密码
    查看>>
    php-redis中文参考手册_Ping_echo_set_get_setex_psetex_...
    查看>>
    Redis使用不当导致应用卡死
    查看>>
    PHP-Shopify-API-Wrapper 使用教程
    查看>>
    php-兔子问题,斐波那契数列
    查看>>
    PHP-希尔排序
    查看>>
    PHP-快速排序的2种实现方法
    查看>>
    Redis使用lua脚本
    查看>>
    php-数据结构-二叉树的构建、前序遍历,中序遍历,后序遍历,查找,打印
    查看>>
    php-有序数组合并后仍有序
    查看>>