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?
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)
Jennifer NordellTreehouse Staff
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!
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]))