Advertisement
ganiyuisholaafeez

Product Function of a List of Numbers

Feb 22nd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. # The function is named product() and it has accept a list of numbers
  2. def product(numbers):
  3.     if len(numbers) > 0:
  4.         multiply = 1            # Setting the base of the multiplication
  5.         for number in numbers:
  6.             multiply *= number # Multiply the iterated numbers
  7.         return multiply
  8.  
  9. print(product([1, 2, 3])) # 6
  10. print(product([4, 5, 6, 7])) # 840
  11. print(product([10])) #10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement