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 trialJennifer Lithgow
11,778 PointsTuples Packing Code Challenge
I'm getting an error that says "couldn't multiply valid values together," but when I copy/paste my code into IDLE and run it there, it seems to work. I don't know what the problem is. . .
def multiply(*args):
to_multiply = []
for x in args:
to_multiply.append(x)
product = to_multiply[0]
count = 1
while count <= len(to_multiply):
product = product * count
count += 1
return product
3 Answers
Steven Parker
231,269 PointsDid you really intend to multiply the product by the count?
I'm guessing you would rather multiply by one of the values you put into your to_multiply array.
Also check your loop to make sure you're running the correct number of times.
Now just a suggestion (it's not necessary to pass the challenge), you could multiply at the same time as you unpack so you would only need one loop (and no local array).
Ioannis Papaioannou
2,967 PointsHi guys, my Python level it's "I'm trying to understand what to change here after Steven's suggestions." Could you give me more hints ? Thanks.
Steven Parker
231,269 PointsJennifer's approach is rather unique, as are my suggestions to her. Your own solution is most likely to be quite different and you will probably not encounter the same issues.
Ioannis Papaioannou
2,967 PointsThank you, I solved it and it was very much easier than I thought. I 'll try with slices as well.
Jennifer Lithgow
11,778 PointsJennifer Lithgow
11,778 PointsThank you so much! I corrected those things and it worked. :)