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 trialShivam Gupta
2,106 PointsWhat is wrong in this Code?
def combiner(nums_str): temp_str = "" temp_nums = 0.0
for i in nums_str:
if type(i) == str:
temp_str = temp_str + i
elif type(i) == int or type(i) == float:
temp_nums = temp_nums + float(i)
return ''.join([temp_str,str(temp_nums)])
def combiner(nums_str):
temp_str = ""
temp_nums = 0.0
for i in nums_str:
if type(i) == str:
temp_str = temp_str + i
elif type(i) == int or type(i) == float:
temp_nums = temp_nums + float(i)
return ''.join([temp_str,str(temp_nums)])
1 Answer
Steven Parker
231,275 PointsThe instructions included this hint: "Be sure to use isinstance
to solve this as I might try to trick you."
I see you used "type" to identify each item, but that might not correctly identify subclasses derived from the built-in types. Try refactoring to use isinstance
as suggested.
Shivam Gupta
2,106 PointsShivam Gupta
2,106 PointsSure, Let me try to get this thing working.
Thanks for your help.