Advertisement
ganiyuisholaafeez

Product Function of a List of Numbers

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