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

Michael Dinnall
Michael Dinnall
6,730 Points

why isnt my function working ? Needed: a break to exit the loop

def loopy(items): for item in items:
if item == 'STOP': break return item

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

2 Answers

Alexandra Barnett
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,473 Points

Hi Michael! I see that you have returned the item if it's not a break? I think the challenge wants you to print the item like this:

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

Hope that helps! Let me know if you have any questions! :)

Michael Dinnall
Michael Dinnall
6,730 Points

Hi Alexandra its still given me "Bummer! Didn't find the right items being printed." I also tried:

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

I still got the same result

Michael Dinnall
Michael Dinnall
6,730 Points

Actually, I just solved it. I was printing (item) not (items). Thanks for your suggestion it made me look into it a little more !