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

can someone please tell what would be wrong in this code

i can't figure it out

instances.py
import math
combiner(data):
    if data.isinstance(int,str):
        text=''
        number=0
        for val in data:
            if val.isalpha():
                text+=val
            else:
                number+=val
        return text+str(number)

2 Answers

Schaffer Robichaux
Schaffer Robichaux
21,729 Points

Hey Pankaj, I haven't had a chance to look at the logic of the script; however, it initially looks like you have forgotten 'def' preceding your declaration of the function 'def combiner (data):'

I added the def (as per Shaffer) but it still didn't work. I am not sure what this script is trying to do or what input it takes, but isinstance doesn't appear to work like you are trying to make it work. It should probably be formatted like:

if isinstance(data, (int, str)):

See the documentation and examples here.

When that runs, you will get an error in your else clause. You need to convert val to an int or it won't concatenate properly.

That's all I got. If you link me to the exercise you are working on or at least tell me what to input and what output to expect, I could be more helpful.