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 trialJohn Cook
5,172 PointsInstances.py Code works upon testing in workstation but fails on the code challenge, does anyone know why?
So here is my full test code:
my_list = ["abc",1,2.0,"efg"]
why are my asignment operators not working?
def combiner(my_list): text = "" number = 0
for item in my_list:
if isinstance(item, str):
print(item)
text += item
elif isinstance(item, (int, float)):
print(item)
number += item
else:
continue
output = [text+str(number)]
return(output)
combiner(my_list)
and below is the code I am using in the code challenge, I get it to return the correct answer but for some reason it is not passing the code challenge.
def combiner(my_list):
text = ""
number = 0
for item in my_list:
if isinstance(item, str):
text += item
elif isinstance(item, (int, float)):
number += item
output = [text+str(number)]
return(output)
2 Answers
John Cook
5,172 Pointswoops it looks like it chopped up the test code, but there it is, anyways I just don't understand why its not passing.
Donald Morales
15,983 PointsHello John!
If you change the square brackets on line 9 to parentheses, the code will run:
output = (text+str(number))
The function is expected to return a string, and the square brackets create a list containing 1 string as its only item.