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

not sure why my code not passing

Not sure why my code not passing

instances.py
def combiner(lst):
    x = ""
    j = 0
    for item in lst:
        isinstance(item[lst],str):
            item[lst] += item[lst]
        isinstance(item[lst],float):
            item += int[item]
            item += item
        return item
Jen Farrant
Jen Farrant
6,905 Points

you are not adding to x and j, which I think is your string and total so += should link to x or j

also, it can be helpful to use variable names which mean something, as it makes your code easier to read.

So x could be called words and j could be called numbers

Thank You Jen, very helpful

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Hi Matthew. There were several issues with your code

  • x should be an empty list [] so that strings found can be appended to it. After the for loop, this list can be joined into a string
  • an if should come before the isinstance function.
  • the isinstance function should take item as it's argument not item[lst]
  • Instead of += to concatenated partial strings. It is better to append to a list, such as x.append(item). then use "".join(x) to get a string from those items after the for loop completes
  • you test for type float but not for type int. Add another if statement for isinstance(item, int).
  • both the float and int checks can use the same j += item to accumulate the numeric total
  • the return statement is intended to far. It should be outside of the for loop. As it is, it will return after the end of the first iteration of the for loop
  • the return statement should return the list x and j both converted to a string

I know that's a lot of comments, but it's helpful to understand each one. Please post back if you have any more questions. Good Luck!!