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! While you're at it, check out some resources Treehouse students have shared here.

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

Python Python Collections (2016, retired 2019) Tuples Packing

i need help on packing tuples challenge

my function is only multiplying the first and last values.How can i fix it?

twoples.py
def multiply(n,*args):
    total=0
    for item in args:
        total= n*item

    return total
Kent Γ…svang
Kent Γ…svang
18,823 Points

It would be nice if you could paste in the challenge description. I don't have access to the challenge

Thanks Jason, I see where I was going wrong and why.

1 Answer

Jason Ziegler
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jason Ziegler
Full Stack JavaScript Techdegree Graduate 39,583 Points

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.