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

Anusha Singh
PLUS
Anusha Singh
Courses Plus Student 22,106 Points

Please help

I just can't figure out that what is the mistake which I made in this code. The question is : 'Oops, I forgot that I will need to break out of the loop when the current item is on "STOP". Help me add that code! ' Now I can't figure out the mistake in the code which I have written below. Please find out the mistake and tell me if possible - A.S.A.P

breaks.py
def loopy(items):
    # Code goes here
    for word in items:
        print(word)
        if word == "STOP":
            break

1 Answer

They want you to not print the word (break out of the loop) if the word is STOP. You printed the word and then broke the loop.

def loopy(items):
    # Code goes here
    for word in items:
        if word == "STOP":
            break
        print(word)