Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,103 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