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

Treehouse: Didn't get the expected output --> But I did! *using instances

Task: Create a function named combiner that takes a single argument, which will be a list made up of strings and numbers.

Return a single string that is a combination of all of the strings in the list and then the sum of all of the numbers. For example, with the input ["apple", 5.2, "dog", 8], combiner would return "appledog13.2". Be sure to use isinstance to solve this as I might try to trick you.

Error: Didn't get the expected output!

I ran my code several times with different objects and I do get the expected result as asked in the task. I don't understand why the error is thrown.

instances.py
def combiner(mixedlist):
    x = ""
    y = 0
    for rec in mixedlist:
        if isinstance(rec,str):
            x += rec
        elif isinstance(rec, int):
            y += rec
    x += str(y)
    return x

I tried, for instance, with this list

a = [10,"bamboo", "ohoh",105, 26, "bo", 9, "last"]

and the result was

treehouse:~/workspace$ python notitle.py
bambooohohbolast150

1 Answer

Spencer Hurrle
Spencer Hurrle
3,128 Points

Kenneth added strings, ints, and floats in the list. You're only catching strings and ints. Looks like you just need to catch those floats