Example #1
0
def runModules():
  # from 5.1.3.3
  #import module

  # from 5.1.3.4
  # main.py

  from module import suml, prodl

  zeroes = [0 for i in range(5)]
  ones = [1 for i in range(5)]
  count1 = [i+1 for i in range(5)]
  count2 = [i*2 for i in range(5)]
  print(suml(zeroes))
  print(prodl(ones))
  print(count1)
  print(suml(count1))
  print(count2)
  print(prodl(count2))
Example #2
0
from module import suml, prodl

zeroes = [0 for i in range(5)]
ones = [1 for i in range(5)]
print(suml(zeroes))
print(prodl(ones))
Example #3
0
from sys import path

path.append('..\\modules')

import module

zeroes = [0 for i in range(5)]
ones = [1 for i in range(5)]
print(module.suml(zeroes))
print(module.prodl(ones))
Example #4
0

def prodl(the_list):
    global __counter    
    __counter += 1
    prod = 1
    for element in the_list:
        prod *= element
    return prod


if __name__ == "__main__":
    print("I prefer to be a module, but I can do some tests for you.")
    my_list = [i+1 for i in range(5)]
    print(suml(my_list) == 15)
    print(prodl(my_list) == 120)

from module import suml, prodl
zeroes = [0 for i in range(5)]
ones = [1 for i in range(5)]
print(suml(zeroes))
print(prodl(ones))

import sys
for p in sys.path:
    print(p)

from sys import path
path.append('..\\modules')
import module
zeroes = [0 for i in range(5)]
Example #5
0
from sys import path

path.append('..\\Modules')

from module import suml,prodl


sumlist = [i+1 for i in range(20)]
prodlist = [j for j in range(1,5)]

print(prodlist)
print(suml(sumlist))
print(prodl(prodlist))
Example #6
0

def prodl(l):
    global __counter
    __counter += 1
    prod = 1
    for el in l:  # Get the product of a list
        prod *= el
    return prod


if __name__ == "__main__":  # "__name__" is a variable. If run a file directly, it's set to __main__ string; if a file is imported as a module, it's set to the file's name.
    print('I prefer to be a module, but I can do some tests for you.')
    l = [i + 1 for i in range(5)]  # Create a list
    print(sum(l) == 15)  # check if the output is equal to 15
    print(prodl(l) == 120)
"""
2. Use the module created in step 1.
"""
from module import suml, prodl  # Selective import

zeros = [0 for i in range(5)]
ones = [1 for i in range(5)]
print(suml(zeros))  # Use the function suml directly instead of module.suml
print(prodl(ones))
"""
3. Create a package, which has a number of modules and sub-packages too.
"""
from sys import path  # Selective import, and sys is another coomon built-in module.
path.append(
    'C:\\Users\\yunfeng.zhao\\PycharmProjects\\PCPP\\Packages\\Extrapack_4_3_24.zip'
Example #7
0
import module as mm

er = [0 for i in range(5)]
mur = [1 for i in range(5)]
print(mm.suml(er))
print(mm.prodl(mur))