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

Didier Borel
Didier Borel
2,837 Points

break from a list

can someone give me the correct answer here and tell me what the problems. I have tried every possible combination of syntax etc, so plsgive me the solution and tell what didn't work. don't tell me to figure it out myself. this

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

2 Answers

Hey Didier,

I got stuck on this too. I eventually figured out that you need to have your if statement before the print items line:

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

And you gotta be careful with the spacing or it won't run properly. Hope that helps!

Hey Bud, not sure what the question is asking but right now the logic of the function is to print every item even the word "STOP". Remember that python reads top to bottom. Maybe try moving the if condition somewhere else and run your function again. :D

Didier Borel
Didier Borel
2,837 Points

I tried that already, (putting print(item) after the break function,) but I still get an error message. so how would you write it? what code would you write in order to print each item in items, and break if the item is "STOP"?

Didier Borel
Didier Borel
2,837 Points

drop it Steve, I got my answer, but thanks for your reply and your effort