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

Michael Allocco
Michael Allocco
616 Points

Am I expected to flesh this code out more, perhaps?

Like, am I supposed to add the list named items and use .append to add the item to it, or is that already done, just off screen? The instructions were simple and I think I followed them concisely. I can't see why my code isn't passing.

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

    if item == "STOP":
        break

3 Answers

andren
andren
28,558 Points

No, your code is as fleshed out as it needs to be. The issue is not the code used but the placement of it. In Python the indentation (horizontal spacing) of code is used to group it, code that belongs to a certain thing (like a loop) needs to be indented to be inside it.

Since the if statement is supposed to check items within the loop it has to be placed within it, currently it exists outside of it due to it being on the same indentation level as the loop declaration. In addition while the task is not super clear about this you are meant to stop the loop the second the "STOP" item appears, meaning you need to place the if statement before the print function since that is not supposed to run in that scenario.

If you fix those two issues like this:

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

Then your code will work.