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

Ryne Ziemba
Ryne Ziemba
9,967 Points

Break loop problem

Why is this code not working to break the loop? I replace item for words and neither one works. Thanks!

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
            break
        print(items)
Ryne Ziemba
Ryne Ziemba
9,967 Points

*or "word", rather, not "words"

2 Answers

You weren't asked to print the actual list; you were asked to print each individual item in the list.

Try using the noun item instead of the plural noun items.

Like this:

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

Good luck! ~alex

Ryne Ziemba
Ryne Ziemba
9,967 Points

Hmmm. I tried that but it still says "Bummer! Try again!"

What's the challenge's question?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I tried this solution and it worked for me (typed it myself, though, not copy/paste). Are you still getting the bummer message? Can you try refreshing the challenge and submitting this code again?

Ryne Ziemba
Ryne Ziemba
9,967 Points

it is this "Oops, I forgot that I need to break out of the loop when the current item is the string "STOP". Help me add that code!"

The prior challenge is "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!" which I solved correctly with:

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

I'm 99% sure that your code is right. I've been looking for errors in your code for 20 minutes now. I think the challenge has some bug...

Tagging Kenneth Love

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Why are you printing items instead of each individual item, which in your code would be word?

I already fixed that in my script.