博客
关于我
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支付宝手机网页支付类实例
    查看>>
    PHP改变数组key值的方法
    查看>>
    php教程之php空白页的原因及解决方法
    查看>>
    PHP数据库操作
    查看>>
    PHP数据文件过大,导致PHP加速器eaccelerator在PHP5.2版本下崩溃
    查看>>
    RabbitMQ - 死信、TTL原理、延迟队列安装和配置
    查看>>
    PHP数据访问的多重查询(租房子查询)
    查看>>
    RabbitMQ - 如保证消息的可靠性?(消息确认、消息持久化、失败重试机制)
    查看>>
    RabbitMQ - 基于 SpringAMQP 带你实现五种消息队列模型
    查看>>
    php数组函数分析--array_column
    查看>>
    php数组去重复数据的小例子
    查看>>
    php数组实现:哈希 +双向链表
    查看>>
    PHP数组排序函数array_multisort()函数详解(二)
    查看>>
    php数组的几个函数和超全局变量
    查看>>
    PHP文件上传详解
    查看>>
    PHP文件锁
    查看>>
    php文本框输入制定文本,php – 当用户没有向文本框输入任何内容时...
    查看>>
    PHP时间戳和日期相互转换操作总结
    查看>>
    php时间戳知识点,php 时间戳函数总结与示例
    查看>>
    php更新数据库失败,php – 无法更新MySQL数据库
    查看>>