Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Break

Sean Frye
Sean Frye
1,167 Points

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,830 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,830 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)
Sean Frye
Sean Frye
1,167 Points

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

Sean Frye
Sean Frye
1,167 Points

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