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

Hm. Am I close at all on this?

I feel I followed the video precisely and looked at my notes and understood, but I guess I don't have this. Am I any close on this or am I way off? I think given more practice, I'll get this down, I just am not sure where I am on this.

breaks.py
def loopy(items):
    while True:
        new_item = input("> ")

        if new_item == "STOP":
            break
        items.append(new_item)

    for item in items:
        print(items)
Cooper Runstein
Cooper Runstein
11,850 Points

You don't need the while loop, the challenge wants you to put the break statement in the for loop:

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

3 Answers

Cooper Runstein
Cooper Runstein
11,850 Points

The answer below worked for me, it should work for you too. Notice in your initial attempt you're printing out "items" which is an array, whereas "item" is each individual object in that array. Also Python is super space sensitive, so make sure you're using correct spacing each time.

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

Thank you! I actually had taken a break from studying Python as I had to take care of some serious real life issues, but thank you for showing me the way. It worked. I'm just confused because on the first part, having the bottom line say print(items) passed, but on the 2nd part which I was stuck on here, the bottom line had to say print(item) with no s. That was very confusing to me.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Sean. You are close enough, the for loop it's needed but the while and input() you don't need and it's not required after the for statement you can do

if item == 'STOP':
    break
else:
    print(item)

or

it item != 'STOP':
    print(item)
else:
    break

in both ways it will work. I hope this helps you out. Happy coding

I've tried both of the suggestions here. I still can't pass.