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

Python Python Basics (2015) Shopping List App Break

alexander baldon
PLUS
alexander baldon
Courses Plus Student 427 Points

Task 2 of 2

I don't understand what i am doing wrong. I get the error EOF

breaks.py
items = []

def loopy(items):

    while True:
        new_item = input("> ")
        items.append(new_item)
        if "STOP" in new_item:
            break

    for item in items:
        print(item)

1 Answer

andren
andren
28,558 Points

The items you are looping over is sent in as an argument to the function, you are not supposed to create your own items list by prompting for input. All you have to do is loop over the items list (like you are already doing with the code outside the while statement) and then check if the current item being looped over is equal to "STOP". If it is break, if it isn't print it.

So basically remove your while statement and everything in it, and instead add an if statement to your for loop that simply check if the item is equal to the string "STOP", if it is use the break keyword. Remember to place the if statement above the print statement since the loop should stop as soon as it finds the "STOP" item, it should not print out "STOP" before it stops.