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 trialNataly Rifold
12,432 PointsI keep getting EOFError and I have no idea why
Hi, I keep getting EOFError and I have no idea why, I did every thing form the Removing Items From A List video and I look over my script and I have no idea. I keep getting this message :
Traceback (most recent call last):
File "shopping_list.py", line 79, in <module>
add_to_list(new_item)
File "shopping_list.py", line 26, in add_to_list
"> ".format(item))
EOFError
The code:
def add_to_list(item):
show_list()
if len(shopping_list):
position = input("Where should I add {}? \n"
"Press ENTER to add to the end of the list\n"
"> ".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list.insert(position-1, item)
else:
shopping_list.append(new_item)
show_list()
1 Answer
Dave StSomeWhere
19,870 PointsThere are a few obvious issues and since python is indentation based we need to see formatted to help more.
To post your code check the Markdown Cheatsheet Code section below each post for detailed info. For python on separate lines...
line 1 - three backticks "`" (to the left of the 1 above the tab on a US standard keyboard) followed by the word "python" (no quotes - just used for emphasis)
line 2 through end of code - copy in your code
line n after code - three more backticks
I think the eof error is because of all the quotes in the Input
statement
you are also putting conditions after else:
commands - maybe you intended to use elif
?
Also you are not using double equal signs in conditionals - remember == in an if statement and = for assignment.
The other thing I noticed is you did is not None
which should be != None
Hope that's a start.