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

Ishan Rahman
Ishan Rahman
2,155 Points

Can't seem to get the second challenge

What's wrong?

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

1 Answer

You are soooo close!

You are comparing the string "STOP" to the list that is passed in. You are also printing the whole list.

The item variable is a variable that will change through every iteration of the loop. For example, if I wrote this:

my_list = [1, 2, 3]
for x in my_list:
    print(x)

It would print:

1
2
3

However, if I wrote:

my_list = ['a', 'b', 'c']
for x in my_list:
    print(my_list)

It would print the whole list in each iteration:

['a', 'b', 'c']
['a', 'b', 'c']
['a', 'b', 'c']

Now that you've read these examples, let me point this out:

You are printing the entire list and comparing "STOP" to the entire list.

You only need to compare and print the value of item. Remember that this variable changes though each iteration.

Ishan Rahman
Ishan Rahman
2,155 Points
def loopy(items):
    # Code goes here
    for item in items:

        if item == 'STOP':
            break

        print (items)

I got what you said. I did this but still it doesn't work.

You are still printing items.