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

    你可能感兴趣的文章
    Objective-C实现获取CPU温度(附完整源码)
    查看>>
    ok6410内存初始化
    查看>>
    OpenMMLab | 【全网首发】Llama 3 微调项目实践与教程(XTuner 版)
    查看>>
    Openresty框架入门详解
    查看>>
    openshift搭建Istio企业级实战
    查看>>
    ORACEL学习--理解over()函数
    查看>>
    Oracle 递归
    查看>>
    oracle--用户,权限,角色的管理
    查看>>
    Oracle11G基本操作
    查看>>
    Oracle11g静默安装dbca,netca报错处理--直接跟换操作系统
    查看>>
    Oracle——08PL/SQL简介,基本程序结构和语句
    查看>>
    oracle下的OVER(PARTITION BY)函数介绍
    查看>>
    Oracle中DATE数据相减问题
    查看>>
    oracle中sql的case语句运用--根据不同条件去排序!
    查看>>
    oracle中关于日期问题的汇总!
    查看>>
    Oracle中常用的语句
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org/hibernate/validator/internal/engine
    查看>>
    orm总结
    查看>>
    paddle的两阶段基础算法基础
    查看>>