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

    。。。。。。。。。。

  • 相关阅读:
    HTML初步学习7
    HTML初步学习6
    HTML初步学习5
    HTML初步学习4
    poj3449Geometric Shapes
    poj2074Line of Sight(直线相交)
    2014 Multi-University Training Contest 4
    poj3347Kadj Squares
    poj1556The Doors
    poj3608Bridge Across Islands(凸包间最小距离)
  • 原文地址:https://www.cnblogs.com/mtima/p/2951953.html
Copyright © 2011-2022 走看看