Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
i need help on packing tuples challenge
my function is only multiplying the first and last values.How can i fix it?
def multiply(n,*args): total=0 for item in args: total= n*item return total
Challenge: Let's play with the *args pattern.
Create a function named multiply that takes any number of arguments. Return the product (multiplied value) of all of the supplied arguments. The type of argument shouldn't matter.
Slices might come in handy for this one.
EDIT: ( I found help on this thread )
Regarding your issue: total = n * item, total is being replaced each time, and the previous value for total is being lost. Ex: multiply(1,2,3,4) total = n*item plays out as below: total = 1 * 2 (total = 2) total = 1 * 3 (total = 3) total = 1 *4 (total = 4)
Also be careful making total equal to 0. 0 times any other number is 0.