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 trialYoussef Moustahib
7,779 PointsThis works is the code challenge but not in workspaces?
Hi, my code in the code challenge works great, but when I add some numbers to my arguments in workspaces, it doesn't work. please see my code in workspaces below, then my code in the code challenge:
x = (1,2,3)
y = (4,5,6)
def end(*a):
maxx = 1
for thing in a:
maxx *= thing
print(maxx)
end(x,y)
THIS CODE ABOVE GIVES ME THE ERROR MESSAGE BELOW:
TypeError: can't multiply sequence by non-int of type 'tuple'
MY CODE BELOW WORKS FINE THOUGH. Please help
def multiply(*x):
maxx = 1
for thing in x:
maxx *= thing
return maxx
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsGood question. Argument unpacking is not recursive. When passing two tuples to a function with a *args
signature, only two arguments are seen. The for loop sets thing
to each complete tuple. Thus the multiply fails when applied to two tuples. It would also fail is two lists were passed.