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 trialjdee
6,655 Pointsthis code works in workspaces. Why doesn't it work for the challenge?
Hi, This code works in workspaces. Why doesn't it work for the challenge?
def combiner(items):
# Hold values
strings = ""
nums = 0
# Loop through list
for item in items:
# Test type of each element
# If string, concatenate each to itself
if isinstance(item, str):
strings += item
# else if float or int, add together
elif isinstance(item, (float, int)):
nums += item
print(strings + str(nums))
combiner(["apple", 5.2, "dog", 8])
3 Answers
KRIS NIKOLAISEN
54,972 PointsThe challenge wants you to return the string. You are printing.
jdee
6,655 Pointsdoh!, thanks
James Ball
2,074 PointsI was making the same mistake in a different challenge. Print and return are actually different statements (although they may sometimes have the same behavior). Print only displays an output to the user whereas return gives back a result to the function call. All functions return a value, even if there is no return statement (in which case the function will return None).