def average(values): nvals = len(values) sum = 0.0 for v in values: sum += v return float(sum) / nvals ## my script using the math module ## import mymath # values = [2, 4, 6, 8, 10] print('squares:') for v in values: print(mymath.square(v)) print('Cubes:') for v in values: print(mymath.cube(v)) print('average: ' + str(mymath.average(values))) import mymath as mt print(mt.square(2)) print(mt.square(3))
import mymath mymath.square(6) mymath.cube(4)
## My script using the math module ## import mymath # note no .py values = [2, 4, 6, 8, 10] print('squares:') for v in values: print(mymath.square(v)) print('Cubes:') for v in values: print(mymath.cube(v)) print('Average: ' + str(mymath.average(values)))
import mymath as a values=[1,4,6,8,10] print('squares:') for v in values: print(a.square(v)) print ('cubes') for v in values: print(a.cube(v)) print('average:'+ str(a.average(values)))
from mymath import square from mymath import cube square(6) cube(4)
import mymath as th values = [2, 4, 6, 8, 10] print('square:') for c in values: print(th.square(c)) print('cubes:') for c in values: print(th.cube(c)) print('Average: ' + str(th.average(values)))
import mymath mymath.sqr(5) mymath.cube(6)
from mymath import sqr from mymath import cube sqr(5) cube(7)