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 Muddle Fuddle

Did anyone interpret the "type shouldn't matter" as meaning that the answer should account for non-number data types? Unfortunately, the code below (even though it works as expected in the IDLE) will not pass the challenge. I tried another version (that also works as expected in the IDLE) and it did not pass either. Turns out, it you remove the "float()" [and the "try... except" as it's no longer needed if you're not using float] then it works! Why is that?

def multiply(*args):
    product = args[0]
    for arg in args[1:]:
        try:
            arg = float(arg)
        except:
            continue
        else:
            product *= arg
    return product

2 Answers

Steven Parker
Steven Parker
229,744 Points

The float() function forces the type to change.

If the work checker passes in a list of integers, it may expect an integer to be returned. But the code above would return a float instead.

Thanks, Steven- I was using int() at first and later switched to float(). Maybe another data type was used besides numbers (a single string in a number sequence would work in multiplication) and like you say, the code is forcing a change type (and by passing anything that doesnt change).