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

How do I solve breaks.py Challenge 2 of 2

I don't see what I am doing wrong. Here are the details. Keep in mind I was not ask to create any list.

Challenge:Task 2 of 2 Oops, I forgot that I need to break out of the loop when the current item is the string "STOP". Help me add that code!

Error Msg: Bummer! Didn't find the right items being printed.

My Code: def loopy(items): for i in items: print(i) if i == "STOP": break

def loopy(items):
    for i in items:
        if i == "STOP":

2 Answers

Daniel Schmidt
Daniel Schmidt
9,780 Points

Try this:

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

After taking Antonio's advice and seeing your code it makes total sense. Thanks for replying with visuals @ Daniel !

Antonio De Rose
Antonio De Rose
20,884 Points

you are so close, one thing I would want to emphasis is, if the 1st variable itself to have the value 'STOP', it should break out, without printing, your case it does print, regardless, hence you got to check for the value STOP, and then print it.

@ Antonio I see the logic. Thank you for your reply.