def calculate(x): difference = MyMath.subtraction(MyMath.maximum(x), MyMath.minimum(x)) addition = MyMath.add(MyMath.maximum(x), MyMath.minimum(x)) summation = MyMath.sumTotal(x) numEven = MyMath.evenNum(x) finalList = checkClear(x) return ( "The difference is:%d The summation is:%d The summation of all input is:%d The number of even numbers is:%d The values in the list are: %s" % (difference, addition, summation, numEven, finalList))
def main(): numberslist = checker() biggestnumber = MyMath.maximum(numberslist) smallestnumber = MyMath.minimum(numberslist) difference = MyMath.subtraction(biggestnumber, smallestnumber) bigsmallsum = MyMath.add(biggestnumber, smallestnumber) listsum = MyMath.sumTotal(numberslist) evencount = len(MyMath.evenNum(numberslist)) if smallestnumber < 5: numberslist = MyMath.clear(numberslist) output = "The difference is:%d The summation is:%d The summation of all input is:%d The number of even numbers is:%d The values in the list are: %s" \ %(difference, bigsmallsum, listsum, evencount, str(numberslist)) print(output)
# Python 2.7.X # Try_006.py # Modules # Objective: Create a new module and import it # to this script # Requirement 1: Create a new script called # MyMath.py, then add 5 functions we created from # Works_Try_004 and 005. # Requirement 2: Using imported module, perform # 5 functions with given variables a = 2 b = 8 # Writer your code here import MyMath print "A + B:", MyMath.add(a, b) print "A - B:", MyMath.sub(a, b) print "A * B:", MyMath.mul(a, b) print "A / B:", MyMath.div(a, b) print "A ^ B:", MyMath.exp(a, b)
import MyMath print("10+10=", MyMath.add(10, 10), sep="") print("10-10=", MyMath.sub(10, 10), sep="") print("10*10=", MyMath.mul(10, 10), sep="") print("10/10=", MyMath.div(10, 10), sep="") print("10**10=", MyMath.power(10, 10), sep="")
1.将模块所在路径,手动加入到sys.path中 #sys.path.append("G:\projects\python\module\package1") 2.将自定义模块,发布到系统目录 发布自定义模块的步骤: 1.确定发布的模块(目录结构) |--setup.py |--package1 |--自定义模块 MyPath 2.setup的编辑工作 setup() 3.构建模块 python setup.py build 4.发布模块 python setup.py sdist 2.模块的安装 2.1 通过命令完成安装(推荐) 更安全 a.找到之前发布的压缩包,解压操作 b.python setup.py install 2.2 暴力安装 文件拷贝 """ # import sys # list1 = sys.path # for i in list1: # print(i) import MyMath print(MyMath.add(6, 12))