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

Spencer Heflin
Spencer Heflin
7,389 Points

Part 2 of Shopping List Code Challenge

I'm not sure what I'm doing wrong on this part. I feel like I'm missing something obvious, but I can't figure out why the break isn't working. Any help would be greatly appreciated.

breaks.py
def loopy(items):
        print(items)
            if items == 'STOP':
                break
Spencer Heflin
Spencer Heflin
7,389 Points

sorry new_item should actually be items. I was trying a bunch of different things and forgot to change it back.

Greg Kaleka
Greg Kaleka
39,021 Points

Hey Spencer,

For future reference, you can edit your posts and answers and comments by clicking on the three-dots icon below your post, and choosing edit. I took the liberty of changing it for you, which I can do because I'm a moderator. :blush:

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Spencer,

Normally I wouldn't just give an answer, but you've pretty much got it solved. Your indentation is a little wonky, and your for loop is gone! You obviously had it in there for Challenge Part 1, so I'm gonna just put it back in there. Let's also make sure we break before printing the item if the item is "STOP" (I'm not sure it's required, but seems like the right thing to do):

solution.py
def loopy(items):
    for item in items:
        if item == 'STOP':
            break
        print(item)

Let me know if anything doesn't make sense. Also - DON'T COPY AND PASTE! Typing it out is helpful :blush:

Cheers :beers:

-Greg

Spencer Heflin
Spencer Heflin
7,389 Points

Awesome thanks for your help.