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

I need help

i don't know what I have done wrong in my code

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        print(item)

        item == "STOP":
        break

What part of the code challenge are you referencing with your code? There's 2 parts to this challenge.

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

You need to use the if...else clause here; also, the condition check goes before print(item), and only output item if the condition check fails.

def loopy(items):
    # Code goes here
    for item in items:
        if item=='STOP':  # condition check for whether item == 'STOP'
            break         # if so break out of the loop
        else:             # otherwise
            print(item)   # output item

hope it helps.