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 trialFredrik August Madsen-Malmo
16,261 PointsPutting the "Fun" Back in "Function" | Stage 5 - can't write str to text stream
list1=[1,2,3]
def add_list(list):
sum = 0
for number in list:
sum = sum + number
return sum
b= add_list(list1)
print(b)
When I run this code, I get an error saying "can't write str to text stream". I see no reason for this code not to pass, so I'm wondering if I'm doing something wrong.
Thanks, Fredrik A. Madsen-Malmo
2 Answers
Stone Preston
42,016 Pointsit may be because your function add_list returns an integer which would have to be converted to a string before it could be printed.
You dont need to call your function or print anything out. simply define the function. thats all you need. adding anything else may cause the challenge engine to not accept your code:
your function is correct. so all you need to type for task 1 is:
def add_list(list):
sum = 0
for number in list:
sum = sum + number
return sum
note: list is keyword in python so you may want to change your parameter name to something different:
def add_list(some_list):
sum = 0
for number in some_list:
sum = sum + number
return sum
Kenneth Love
Treehouse Guest TeacherJust tested your answer and it gets past the first step of the CC, so you should be good to try and finish it.
Fredrik August Madsen-Malmo
16,261 PointsFredrik August Madsen-Malmo
16,261 PointsThanks a lot! I will try your version and let you know if it works.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher.format()
converts things to strings, so the wrapping shouldn't be required.Our CC engine is having some issues the last day or two, so that's likely the cause of it malfunctioning.
Fredrik August Madsen-Malmo
16,261 PointsFredrik August Madsen-Malmo
16,261 PointsThanks.