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 trialKiran K
1,029 PointsPlease explain why I'm getting an error (Bummer) when submitting code. The function is returning string as expected.
The combiner function is returning string as expected.
combo = ["apple", 5.2, 8, "dog"]
numberlist = []
stringlist = []
def combiner(item):
for x in combo:
if isinstance(x, str):
stringlist.append(x)
else:
numberlist.append(x)
num1 = sum(numberlist)
str2 = "".join(stringlist)
str3 = str2 + str(num1)
return str3
result = combiner(combo)
print(result)
2 Answers
KRIS NIKOLAISEN
54,972 PointsYour parameter is item so you should iterate with that.
for x in item:
Currently your function only returns the results for list combo so if the checker were to submit for example
result = combiner(["test", 1, 2, 3])
the result would still be appledog13.2
Kiran K
1,029 PointsThank you Kris for your feedback. It worked.
combo = ["apple", 5.2, 8, "dog"]
def combiner(item): numberlist = [] stringlist = [] for x in item: if isinstance(x, str): stringlist.append(x) else: numberlist.append(x)
return "".join(stringlist) + str(sum(numberlist))
combiner(combo)