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

Tuple Issue

I have tired to work on this offline i have found that the solution i used on my home computer does not pass for this challenge, can anyone help me as to why?

twoples.py
def multiply(values):
    total = 1
    for num in values:
        total = total*num
    return total

2 Answers

Stuart Wright
Stuart Wright
41,118 Points

Your code is correct in that it works for multiplying together numbers, it just isn't quite what the challenge is asking you to do. Your code will work if you pass in a list or tuple of numbers as a single argument which you have called 'values'. However, what the challenge asks you to do is create a function which allows you to pass in any number of arguments (presumably floats and/or integers), and multiply them together. The arguments which will be passed in are not combined into a single list or tuple before the function call.

The correct syntax for achieving this is to declare the function as follows:

def multiply(*args):

This means that the function accepts any number of arguments. The only other change you have to make is related to this. Because you are no longer passing in a single 'values' variable, you need to reflect this in the loop:

for num in args:

With these two changes your code should pass correctly.

Ok thanks alot