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

Ashley Keeling
Ashley Keeling
11,476 Points

I am not sure why this function wont work

I don't know why , and it looks similar to the add function in the video

twoples.py
def multiply(*args):
    nums=*args
    total = 0
    for num in nums:
        total = num * num
    return total

I think your problem is this line.

nums=*args

Maybe you want = ?

You could also rename args to nums, and remove this line. There is nothing special about the name args, only the * in front of it.

your total is going to be the last number in the list of *args squared. Also your total is set to 0 so if you fix the first problem, your total will always be 0.

1 Answer

Steven Parker
Steven Parker
230,995 Points

Here's some hints:

  • you don't need "nums", you can iterate using "args"
  • the "total" needs to be the result of multiplying all numbers together, not just the square of one of them
  • you might need to start total with 1 instead of 0
Ashley Keeling
Ashley Keeling
11,476 Points

how do you multiply the numbers together instead of squaring them

Steven Parker
Steven Parker
230,995 Points

For each item in the loop, you might multiply it by the previous total and store it back into the total:

    total = 1          # start with 1 because "0 * anything" is still 0
    for num in args:
       total *= num    # this is the same as "total = total * num"
Ashley Keeling
Ashley Keeling
11,476 Points

thanks I passed the challenge now!!