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

Mujahid Chowdhury
Mujahid Chowdhury
5,108 Points

Can anyone help to explain this one?

I dont understand this. Can someone please explain?

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

3 Answers

Mujahid Chowdhury
Mujahid Chowdhury
5,108 Points

I really appreciate your help Alexander but unfortunately this still doesn't work. Any other suggestions?

Oh I am so sorry! I typed "items" (the one inside the print function) instead of "item" try this instead:

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

Hope that works!

Great job! :thumbsup: However, there are some mistakes in here. First, instead of "for True", you should do "for item in items" like this:

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

Also, you can just say item in items == "STOP", or Python will think you wanted to say "if this list has 'STOP', then break out of the loop.". You don't want that, so you should check if the current item is STOP like this:

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

This step is optional, but it makes the code a little cleaner. You don't need the "else" condition, because if item is "STOP", the "break" keyword will break out of the loop, making that the very last line been run. This is the best way to do this challenge:

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

Hope that helps! :dizzy: