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

Umair iqbal
Umair iqbal
910 Points

Whats wrong

whats wrong

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'm not sure if you're on Step 1 or Step 2 of the challenge. If you're working on step 1 you'll need to remove the if statement. Step 1 only requires that we print out each individual items in the items list. You've chosen to name each individual item words. That should be what you're printing out.

If you're working on step 2 the same thing applies as step 1. Your item is named words. But you're comparing item to "STOP". But the variable item is undefined in your code. You only have defined wordsand items. Also, check your order and indentation. The check for the words being equal to "STOP" needs to come first, otherwise it will print out "STOP" as well. And the if statement should be indented inside the for loop.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Umair iqbal
Umair iqbal
910 Points

So i should be comparing words with item, i did that but im still getting that annoying bummer the identation is four spaces right i checked that the order is def then for words then if words=="STOP": break not working

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

At this point, I'm unsure what your code looks like and if it might be simply an indentation error. But using the variable names you defined, this is how the completed code looked:

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

Note this is for Step 2 and will not pass Step 1. We start by defining a function named loopy that takes a list named items. For every individual item named words we will compare words to "STOP". If the item in the items list is "STOP" we break without printing anything. Otherwise we print the item or, as you named it, words.

Hope this clarifies things! :sparkles:

Umair iqbal
Umair iqbal
910 Points

Couldnt thank you enough