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

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

isinstance challenge

Here's my updated code. Im getting an error saying on third line item, str expected but float was found.

instances.py
def combiner(oldList):
    newList=[]

    number=0
    for item in oldList:
        if isinstance(item,str):
            newList.append(item)
        elif isinstance(item,(float,int)):
            number+=item
    newList.append(number)

    return "".join(newList)

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Leo,

The issue is that you are trying to use join on a float, which is the number variable you've tacked onto the end of your newList.

When join tries to join a string with a float, it throws an error. To avoid this, you'll need to convert 'number' to a str before adding it to the newList, like this:

# Remove this...
newList.append(number)
# And replace with...
newList.append(str(number))

Alternatively, you could delete that newList.append(number) line altogether, and only at the very end, concatenate a string version of your number to the string list, like this:

# Remove this line entirely:
# newList.append(number)
# and change the last line to:
return "".join(newList) + str(number)

Either way should fix the problem. Good luck!