asked 183k views
0 votes
Write a function called prod_all that takes any number of arguments and returns their sum. Test the function by using these two tuples (separately) as arguments: (1, 2, 3, 4) & (4,6,8): prod_all(1, 2, 3, 4) # The answer should be 24 prod_all(4, 6, 8) # The answer should be 192 [10]: def prod_all(*args): tupl = (args) total *= n # total = total *n

1 Answer

4 votes

Answer:

from functools import reduce

def prod_all(*args):

prod = reduce(lambda x,y: x *y, args)

return prod

result = prod_all(4,6,8)

print(result)

Step-by-step explanation:

The use of the "*args" passes a tuple of variable length to a python defined function. The function above takes any number of arguments and returns the product using the python reduce module and the lambda function.

answered
User Rolf Bartstra
by
8.0k points