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

    你可能感兴趣的文章
    pandas 重新采样到每月的特定工作日
    查看>>
    pandas :如何删除以NaN为列名的多个列?
    查看>>
    pandas :我如何对堆叠的条形图进行分组?
    查看>>
    pandas :按移位分组和累加和(GroupBy Shift And Cumulative Sum)
    查看>>
    pandas :检测一个DF和另一个DF之间缺失的列
    查看>>
    Pandas-从具有嵌套列表列表的现有列创建动态列时出错
    查看>>
    Pandas-通过对列和索引的值求和来合并两个数据框
    查看>>
    pandas.columns、get_dummies等用法
    查看>>
    pandas.DataFrame.copy(deep=True) 实际上并不创建深拷贝
    查看>>
    pandas.read_csv()的详解-ChatGPT4o作答
    查看>>
    PANDAS.READ_EXCEL()输出‘;溢出错误:日期值超出范围‘;而不存在日期列
    查看>>
    pandas100个骚操作:再见 for 循环!速度提升315倍!
    查看>>
    Pandas:如何根据其他列值的条件对列进行求和?
    查看>>
    Pandas:对给定列求和 DataFrame 行
    查看>>
    Pandas、groupby 和特定月份的求和
    查看>>
    Pandas、Matplotlib、Pyecharts数据分析实践
    查看>>
    Pandas中文官档 ~ 基础用法1
    查看>>
    Pandas中文官档~基础用法2
    查看>>
    SpringBoot+Vue+OpenOffice实现文档管理(文档上传、下载、在线预览)
    查看>>
    Pandas中文官档~基础用法5
    查看>>