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

frank sebring
frank sebring
1,037 Points

it is suggested to use slicing to answer this question.

When i run this on my computer it will generate the correct answer. For example (1, 2, 3, 4, 5) the product is 120 but it doesn't give me credit on treehouse. Any ideas as to why?

twoples.py
def multiply(*args):
    product = 0
    count = 0
    count2 = count + 1

    for i in args:
        if count == 0:
            product = args[0] * args[count2]
            count += 1
        elif count2 < len(args) + 1:
            product = product * count2
            count += 1
            count2 = count + 1
    return product

2 Answers

Hi Frank,

I've never figured out how to use slices for this challenge - but I'm no Python expert!

The way I solved this was to create a loop, like you have done, to loop over all args. Before that, initialize a variable to hold a value of 1 - don't use zero, else the multiplication will come out as zero!

In the loop, multiply the variable (I called it product) by the arg (you called that i). After the loop, return the product.

I hope that makes sense.

Steve.

the way im trying to solve is wit the ----"The type of argument shouldn't matter"---- in mind, for example, test it with this:

test = multiply([6, 2], 15, 10, 2, [6, 2])