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

Otto linden
Otto linden
5,857 Points

What's wrong?

What's wrong whit my code?

breaks.py
def loopy(items):
    for item in loopy:
        print(item)
loopy(milk, water)

5 Answers

Yes correct. Do not copy and paste. Write it yourself, You will not learn otherwise.

The working code should produce the following:

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

items = ['a', 'b', 'STOP', 'c', 'd']
loopy(items)
a
b
STOP
Otto linden
Otto linden
5,857 Points

hmm, i have exactly like ur code but it dosent work?!

Otto linden
Otto linden
5,857 Points

or wait... typed loppy insted of loopy.. my bad! Thank you! :)

First off for item in loopy: is wrong. Your objective is to loop through items, loopy is just the name of the function. So the right way to do it is for item in items:. Second, your last line is not supposed to be there. It is also incorrect. If you wanted to do it that way you would have to do loopy(['milk', 'water']) but don't do that because the instructions don't ask for that. The way to solve the challenge is to stop printing when the item is 'STOP', so you need to add that logic like:

if item == 'STOP':
    break
Otto linden
Otto linden
5,857 Points

Yeah, I have it like this now but it dosent work still...??

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

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

Your indentation of your condition check is off.

Otto linden
Otto linden
5,857 Points

so what should I do? xD

The second block of code is a copy of yours, except it is slight different. Look very carefully at the differences between the first block and the second block.

Otto linden
Otto linden
5,857 Points

Only that the if has no spaces before?

Otto linden
Otto linden
5,857 Points

I tried copy paste it but it didint work, it only says Bummer! Didn't find the right items being printed.

You're welcome.

Otto linden
Otto linden
5,857 Points

bwt next time u help someone whit this, I think it easier to code it like this:

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

Good job. Putting print after condition will make sure 'STOP' is not printed :) You found it.