Brandon Evans8,154 Points
Confused with this solution
I was able to solve this challenge, however I am confused why I am returned a tuple when I call this method, instead of the actual
product I expect to see in console.
This is my code:
def multiply(*args): product = 1 for arg in args: product *= arg return product numbers = 1, 2, 3, 4, 5, 6 print(multiply(numbers))
When I run this in console, the interpreter returns:
(1, 2, 3, 4, 5, 6)
Should I not expect to see a single integer (the product) returned in the console? Or am I misunderstanding something?
Thanks for the help! :)
Steven Parker203,717 Points
The packing operator (*) is causing the tuple "number" to be handled as a single item. It would do what you expect if you passed a number of individual arguments (such as "
multiply(1, 2, 3, 4, 5, 6)"). But when you pass a tuple in, you get the same tuple out.
But to make the function work on an iterable (like "number"), you'd want to remove the "splat": ("