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

Conner Williams
PLUS
Conner Williams
Courses Plus Student 3,305 Points

how do I solve the second half of this challenge?

how do I properly use the break function to end this loop?

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

4 Answers

Ben Reynolds
Ben Reynolds
35,170 Points

Close, you just need to check for 'STOP' before it prints instead of after.

Conner Williams
Conner Williams
Courses Plus Student 3,305 Points

I'm still having trouble with completing this. I thought I understood your suggestion but it isn't translating for me.

Ben Reynolds
Ben Reynolds
35,170 Points

Can you share the last version of the code that you've tried?

Conner Williams
Conner Williams
Courses Plus Student 3,305 Points

def loopy(items): for item in items: new_item = input('> ') if new_item == 'STOP': break print(item)

Ben Reynolds
Ben Reynolds
35,170 Points
  1. Delete the new_item = input line, you don't need an input for this one
  2. Set the variable names in the "if" and "print" statements back to "item" again
Conner Williams
Conner Williams
Courses Plus Student 3,305 Points

GOT IT !!! thanks for the help. Is that actually as tricky as it seems or was I just not paying attention?

Ben Reynolds
Ben Reynolds
35,170 Points

Haha believe me, one day you will look back on this one and go "how did i not see it??" Try not to facepalm as hard as I did :)

It gets easier, but there's no secret trick to it. Just gotta practice practice practice and over time it starts to stick.