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

instances.py / OO Python course

Can someone help me here? I don't know what I'm doing bad and the bummer just said "Try again!".

Please help!

instances.py
def combiner(*args):
    entrada = list(args)
    cadena = ""
    numeros 0

    for value in entrada:
        if isinstance(value, (str, int, float)):
            if isinstance(value, str):
                cadena += value
            elif isinstance(value, (float, int)):
                numeros += value

    combinacion = cadena + str(numeros)
    print(combinacion)

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

You are very close!

  • def combiner(args): # don't use the star syntax
  • numeros = 0 # add missing assognment
  • return combinacion # use return not print

Post back if you need more help. Good luck!!!

Ankoor Bhagat
Ankoor Bhagat
1,097 Points

This runs perfectly in Jupyter notebooks, but fails in Treehouse challenge...Frustrating experience!!!

def combiner(series):
    strings = ''join([s for s in series if isinstance(i, str)])
    numbers = str(sum([n for n in series if (isinstance(n, int)|isinstance(n, float))]))
    return strings + numbers

>>> combiner(['apple', 5.2, 'dog', 8])
>>> 'appledog13.2'
Ankoor Bhagat
Ankoor Bhagat
1,097 Points

I pasted the wrong version here. I had corrected the . and i mistake. I usually work on Jupyter Notebook and paste stuff. The only thing I changed was isinstance(n, (int, float)) and it worked. The problem is that I do not get error trace on Treehouse platform so it is difficult.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

I wonder if there was something in how you had used a bitwise-or | instead of a logical or.