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

Justin White
Justin White
4,545 Points

Tuples multiply(*args)

I am really having a hard time with this one. Can someone point me in the right direction?

Thank you!

twoples.py
def multiply(*args):
    product = 0

    for num in args:
        product = product * num

    return product
Justin White
Justin White
4,545 Points

I found that it works if I change product to 1 instead of 0. However, I still don't understand what this is doing here. Can someone explain to me what this code is actually doing?

Thank you

1 Answer

Steven Parker
Steven Parker
231,269 Points

Anything multiplied by 0 is 0.

So if you start with 0, no matter how many things you multiply with it, you'll still have 0.

On the other hand, if you start with 1, the first time you multiply you will get the value it was multiplied with. Then the product continues to increase with each other multiplier, exactly as the challenge expects.

Justin White
Justin White
4,545 Points

Thank you. I don't know what is wrong with my brain today. It just went over my head a little.