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

Hanifah W
Hanifah W
395 Points

breaks.py assitance

here is the instructions: 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. But, if the current thing is the string "STOP", break the loop.

Not sure what I'm not seeing?

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

loopy(items)
Hanifah W
Hanifah W
395 Points

figured it out by reading other responses.

def loopy(items): # Code goes here for things in items: if things == 'STOP': break else: print(things)

2 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,074 Points

Yes, like like Hanifah said, you have to print every thing in items that is not "STOP", if it is you have to break the loop. Like this:

def loopy(items):
    # Code goes here
    for thing in items:
        if thing == "STOP":
            break
        else:
            print(thing)

I hope that helps a little bit.

Hanifah W
Hanifah W
395 Points

Thanks Jennifer. I originally had the print command with else: but it gave me a bummer. Strange. Anyway, thank you for your help with this.