zoukankan      html  css  js  c++  java
  • 简单的计算器

    python实现。

    上代码:

    callib.py

    #!c:/python33/python.exe
    
    #
    def plus(number_one, number_two):
        return number_one + number_two
    
    #
    def minus(number_one, number_two):
        return number_one - number_two
    
    #
    def multiplication(number_one, number_two):
        return number_one * number_two
    
    #
    def divide(number_one, number_two):
        return number_one / number_two
        

    cal.py

    #!c:/python33/python
    
    import callib
    from sys import argv
    
    try:
        op = str(input("请输入计算方式(+,-,*,/): "))
        first_number = float(input("第一个数: "))
        second_number = float(input("第二个数: "))
        
    except Exception:
        print("parameter error, please try again.")
        exit()
    
    
    if op == '+':
        result = callib.plus(first_number, second_number)
    elif op == '-':
        result = callib.minus(first_number, second_number)
    elif op == '/':
        result = callib.divide(first_number, second_number)
    elif op == '*':
        result = callib.multiplication(first_number, second_number)
    else:
        print("计算方式不合法!")
    
    result_tips = "结果是: " + str(first_number) + op + str(second_number) + '=' + str(result)
    print(result_tips)

    运行cal.py

    。。。。。。。。。。

  • 相关阅读:
    java中 == 与equals 的区别
    java中的多线程 // 基础
    MySQL-锁机制
    将博客搬至CSDN
    MySQL-事务
    MySQL-存储过程
    MySQL-触发器
    MySQL-视图
    Redis设置Auth认证保护
    PHP目前常见的五大运行模式
  • 原文地址:https://www.cnblogs.com/mtima/p/2951953.html
Copyright © 2011-2022 走看看