Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # multiplier.py
- import sys
- def multiplier(pList:list):
- result = 1
- for n in pList:
- result*=float(n)
- # for
- return result
- # def multiplier
- if __name__=="__main__": # was I called from the CLI?
- if(len(sys.argv)>1): # check if there are args
- the_values:list = sys.argv[1:] # except the script name
- the_mult = multiplier(the_values)
- the_output =\
- f"The mult of {the_values} is {the_mult}"
- print(the_output)
- # if
- else:
- the_output = "Please provide some numbers."
- print(the_output)
- # if-else
- else: # for example, it was an import
- pass
- **********************************************
- # test_multiplier
- # from module import function_name
- from multiplier import multiplier
- def test01():
- TEST_VALUES = [1, 2, 3]
- EXPECTED_RESULT = 6
- bOK:bool =\
- EXPECTED_RESULT == multiplier(TEST_VALUES)
- assert (bOK)
- # def test01
- #test01() # DO NOT DO THIS IF USING PYTEST
Advertisement
Add Comment
Please, Sign In to add comment