am_dot_com

CN 2023-03-17

Mar 17th, 2023 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. # multiplier.py
  2. import sys
  3.  
  4. def multiplier(pList:list):
  5. result = 1
  6. for n in pList:
  7. result*=float(n)
  8. # for
  9. return result
  10. # def multiplier
  11.  
  12. if __name__=="__main__": # was I called from the CLI?
  13. if(len(sys.argv)>1): # check if there are args
  14. the_values:list = sys.argv[1:] # except the script name
  15. the_mult = multiplier(the_values)
  16. the_output =\
  17. f"The mult of {the_values} is {the_mult}"
  18. print(the_output)
  19. # if
  20. else:
  21. the_output = "Please provide some numbers."
  22. print(the_output)
  23. # if-else
  24. else: # for example, it was an import
  25. pass
  26.  
  27. **********************************************
  28.  
  29. # test_multiplier
  30. # from module import function_name
  31. from multiplier import multiplier
  32.  
  33. def test01():
  34. TEST_VALUES = [1, 2, 3]
  35. EXPECTED_RESULT = 6
  36.  
  37. bOK:bool =\
  38. EXPECTED_RESULT == multiplier(TEST_VALUES)
  39.  
  40. assert (bOK)
  41. # def test01
  42.  
  43. #test01() # DO NOT DO THIS IF USING PYTEST
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment