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 trialAlex Golden
4,098 PointsFor Combiner Question in OOP section of Python Track: The following code yields the correct answer, but won't take?
stuff = ["apple", 5.2, "dog", 8]
def combiner(list): wrds = "" nums = 0
for item in stuff:
if isinstance(item, (int, float)):
nums += float(item)
elif isinstance(item, str):
wrds += item
return wrds + str(nums)
print(combiner(stuff))
def combiner(list)
werds = ""
numers = 0
for item in stuff:
if isinstance(item, (int, float)):
numers += float(item)
elif isinstance(item, str):
werds += item
return werds + str(numers)
print(combiner(["apple", 5.2, "dog", 8]))
1 Answer
KRIS NIKOLAISEN
54,971 PointsLooking at the code on the bottom I see a few issues:
- There should be a colon after
def combiner(list)
- You pass in
list
but then iterate overstuff
. In doing so you will always return "appledog13.2" regardless of what is passed in. It should befor item in list:
-
return
statement should be outdented so it lines up withfor
Alex Golden
4,098 PointsAlex Golden
4,098 PointsThank you Kris! The code worked fine in the workspace and I couldn't figure out why it was failing the code challenge. Onward!