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

Seharsh Baxi
Seharsh Baxi
795 Points

Help with functions

I made the loop with the break and followed the directions as asked but it is not working. Please explain what I did wrong

Directions: I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items. But, if the current thing is the string "STOP", break the loop.

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

3 Answers

Julian Gutierrez
Julian Gutierrez
19,201 Points

The for loop is inside the function so you need to indent everything after the first line once.

def loopy(items):
    for item in items:
        if item == "STOP":
            break
        else:
            print(item)
Jeff Hartl
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeff Hartl
Python Web Development Techdegree Student 8,420 Points

Hi Seharsh,

Python is picky about indentation. At least one of your lines of code is not indented correctly.

(EDIT): Oh darn, Julian beat me to it!

Seharsh Baxi
Seharsh Baxi
795 Points

The more responses, the better. Thank you a lot.

Robin *
Robin *
5,670 Points

You just messed up the indents It should be:

def loopy(items):
    for item in items:
        if item == "STOP":
            break
        else:
            print(item)
Seharsh Baxi
Seharsh Baxi
795 Points

I didn't know indents mattered so much in python. Thanks!