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

what is wrong with my breaks.py

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

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

8 Answers

Rich Zimmerman
Rich Zimmerman
24,063 Points

You just need to have it print item AFTER the conditional check for "STOP", this way "STOP" isn't printed.

still not work:

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

Rich Zimmerman
Rich Zimmerman
24,063 Points

Make sure your print line is not indented with the break.

def loopy(items):
    for item in items:
        if item == "STOP":
            break
        print(item)

Indentation is very important with python

MY print line is not indented with the break, just checked one .more time.

it however can't get through , even though i copy and paste your code above

Also , I really cann't see any needs for "STOP", didn't understand why we need a condition to very == "STOP"

Challenge Task 1 of 2

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. Reminder: Check your syntax and indenting!

is there any sign of requiring a "STOP" conditional check?

Rich Zimmerman
Rich Zimmerman
24,063 Points

I'm not sure then, there must be an error somewhere because my code works for the challenge. Double check your spacing or maybe you're missing a semi-colon or something.

The conditional check for "STOP" is in Task 2 of the challenge.

Hi Rich, Can you help paste ur code here ? Thanks so much

Rich Zimmerman
Rich Zimmerman
24,063 Points

Same code as above. For task 1 you just want the loop:

def loopy(items):
    for item in items:
        print(item)

In task 2 you're adding the conditional statement within the loop

def loopy(items):
    for item in items:
        if item == "STOP":
            break
        print(item)

Thanks Rich, I got it, I add "conditional stop" a bit ahead in task 1, that is why it always failed .