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

Khaleel Yusuf
Khaleel Yusuf
15,208 Points

Isn't this code correct?

Isn't this code correct? I've tried many times but it doesn't work. I would like it if you gave me the code.

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

3 Answers

Hello there!

First you are looking on a collection but prints this collection instead of the items you get. This is certainty what you want to do.

for item in items:
    print(item)

Second, you seem to have a problem here with your if statement that checks if the collection is equal to a value. Which will be false/wrong. And I assume that your want to break your for loop if one of the item in items is equal to "STOP".

Lastly, you try to use break outside of a loop. Which will not work. Your if block must be indented once more.

Something along those lines could do the work:

def loopy(items):
    for thing in items:
        if thing == "STOP":
            break
        print(thing)
    # Now you're out of your for loop
    # code some more.
Khaleel Yusuf
Khaleel Yusuf
15,208 Points

It says: "Bummer! Didn't find the right items being printed."

Oh I see. Check my initial anseer, I'll update it.

What's the exact error? There's probably a problem related to the type of thing or items