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 trial
Amanda Flagg
1,716 PointsEOF Errors in Python Basics
I keep getting the error "Bummer! EOFError: EOF when reading a line" in the functions code challenge task. I haven't had any issues with code challenges up until this point.
My code runs perfectly fine in the workspace, so I'm not sure what I could be doing wrong here. Can anyone help?
Here is my code:
this_list = []
def add_list():
print("Enter items for your list. Enter 'DONE' when you are done.")
while True:
new_item = input("> ")
if new_item == 'DONE':
break
this_list.append(new_item)
print("Item added! There are {} items in your list.".format(len(this_list)))
continue
list_sum = map(int, this_list)
print("Here's your list:")
print(sum(list_sum))
add_list()
2 Answers
Anthony Liu
11,374 PointsYou have a lot of unnecessary code All you need are components the prompt asks for.
First: Make a function named add_list that takes a list.
def add_list(a_list):
Second:The function should then add all of the items in the list together and return the total. We probably want to create a variable to represent the total we get after adding the list
def add_list(a_list):
total = 0
return total
Third: Assume the list contains only numbers. (This just means we won't need to write any code to filter the list)
Fourth: You'll probably want to use a "for" loop.
for number in a_list:
Fifth: You will not need to use input(). (We won't have to worry about asking the user for a list so we don't have to worry about this step.)
Lastly: We need to create code so we can add all the items in the list together and return the total. We probably want to write this inside the for loop.
def add_list(a_list):
total = 0
for number in a_list:
# code to add "number" to "total"
return total
Amanda Flagg
1,716 PointsThanks for the detailed explanation! I realized after reading that other thread that I was overcomplicating the code, but it's helpful to see it all written out.
Kenneth Love
Treehouse Guest TeacherI've added a further note to the CC about not needing input(). I'll try to check for the use of input() and issue a special warning after the holiday is over.
Amanda Flagg
1,716 PointsThanks Kenneth!
Amanda Flagg
1,716 PointsAmanda Flagg
1,716 PointsI found another thread that helped (https://teamtreehouse.com/forum/unable-to-understand-python-functions-challenge).
I think the issue here was a misunderstanding of the prompt for the code challenge. Because you come right out of a video about making functions and utilizing inputs, I assumed the same would be applied to the code challenge for functions.