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 Tuple Swapping

Youssef Moustahib
Youssef Moustahib
7,779 Points

Why won't this pack?

def new(*args):

total = 0
for thing in args:
    total += thing
print(total)

x = (1,2,3)

y = (4,5,6)

new(x,y)

Why won't this pack? Help appreciated.

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Youssef,

You've declared x as a tuple (1, 2, 3). Also, you've declared y as a tuple (4, 5, 6). Therefore you are passing two arguments into your function, both tuples. You've declared total as an int (0). You can't add a tuple to an int.

What you can do is unpack x and y into their individual elements when you call the function (so in effect you are passing six arguments into your function, all ints):

new(*x, *y)

Hope that helps,

Alex