创建一个模块calculator.py,完成任意两个数的加(add)、减(sub)、乘(mult)、除(div)运算;导入该模块,分别调用其中的函数,完成如下操作: 1、25+56 2、86-68 3

版权声明:本文为博主原创文章,未经博主允许不得转载。如若转载,请注明出处! https://blog.csdn.net/Homewm/article/details/78240877

 模块calculator.py

#-*- coding:UTF-8 -*-
__author__ = "zhangguodong"
__time__ ="2017.09.29"

def add(a,b):
    return a+b

def sub(a,b):
    return a-b

def mult(a,b):
    return a*b

def div(a,b):
    return a/b

主文件程序14.py

#-*- coding:UTF-8 -*-
__author__ = "zhangguodong"
__time__ ="2017.09.29"

from calculator import add, sub, mult, div
# a = float(raw_input("Input the first number:"))
# b = float(raw_input("Input the second number:"))

operator = {'+':add,'-':sub,'*':mult,'/':div}

def Input(a,o,b):
    print "%s%s%s=%s"%(a,o,b,operator.get(o)(a,b))

Input(25,"+",56)
Input(86,"-",68)
Input(50,"*",60)
Input(99,"/",25)

输出结果和截图:

25+56=81
86-68=18
50*60=3000
99/25=3



展开阅读全文

没有更多推荐了,返回首页