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

Combiner code works in my local console, but does not pass...

The code I have written works in my console when I run it in my terminal, but for some reason it does not pass the task here. Is there something that I should be doing differently?

instances.py
def combiner(strnum_list):
    string = ""
    num = 0
    for item in strnum_list:
        if isinstance(item, str):
            string += item
        elif isinstance(item, (int, float)):
            num += item
        else:
            raise TypeError("The values of the list can only be numbers or strings")
    return string + str(num)

I also tried to check if the item was a bool in the elif statement since True is an instance of the int class, but that still does not pass.

2 Answers

Your code passed the challenge for me. Sometimes if you move things around or you paste in code from somewhere else (like your editor or terminal) it will not work. Try rewriting it and see if it passes.

Also, the challenge doesn't say anything about error handling, so it's not necessary to have the else statement in there. It will just skip over things that are not int, float or string.

Thanks! I swear I tried again and again and in the end, it came down to just retyping everything into the Treehouse IDE...I've run into so many issues like this where my code is actually right, but for some reason it won't pass Treehouse and retyping it somehow fixes everything.

pet
pet
10,908 Points

I removed the

    else:
        raise TypeError("The values of the list can only be numbers or strings")

and it worked fine.