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

Nick B.
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Nick B.
Full Stack JavaScript Techdegree Graduate 31,101 Points

OOP Code Challenge Help Needed!

I seem to get the right answer with this approach, but I keep getting prompt to try again. Could any help me figure this out, please?

instances.py
list1 = ["apple", 5.2, "dog", 8]

def combiner(list1):
tmp = []
tmpint = []
result1 = ""
result2 = ""
for char in list1:
    if isinstance(char, str):
        tmp.append(char)
        result1 = ''.join(tmp)
    elif isinstance(char, (int, float))
        tmpint.append(char)
        result2 = str(sum(tmpint))

return (result1 + result2)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Nick B. ! You're doing terrific and your logic is spot on, but you need to rethink your syntax here a bit. First, you will not need to declare list1 as that will be passed to the function from Treehouse. The biggest problems here are that your code is not indented inside the function definition. I would expect everything below def combiner(list1): to be indented one to the right. Finally, you have a syntax error on the elif as it is missing a colon : at the end of that line.

Once I fix these things, it passes with flying colors! Hope this helps! :sparkles:

Hi Please check if this works for you. It did worked for me.

def combiner(my_list):
    string = ""
    sum = 0
    for item in my_list:
        if isinstance(item, str):
            string += item
        elif isinstance(item, (int, float)):
            sum += item

    final_string = string + str(sum)
    return final_string

print(combiner(["apple", 5.2, "dog", 8]))