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

Andrew Bruce
Andrew Bruce
7,822 Points

Code works on my machine but doesn't satisfy the challenge

Hello,

I have tested this code on my own machine and it works fine, so not sure why it isn't satisfying the challenge.

I have found code in the community to pass the challenge but I'm keen to know why this fails?

Thanks in advance!

instances.py
def combiner(list):
    total = 0
    output = ""
    for item in list:
        if isinstance(item, str):
            output += item
        elif isinstance(item, int):
            total += item
    output += str(total)
    return output

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

The input list of items can be thought of as "string" and "non-string". With this in mind, the elif isinstance(item, int): can be replaced with a simple else:.

Stuart Wright
Stuart Wright
41,120 Points

I think it’s because you only check for int, not float, which is also a numeric type.

As an aside, you shouldn’t really name your variable ‘list’ since it’s a built-in type, although I’m not sure that would cause your code to fail the challenge.