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

Shih Kai-Wen
Shih Kai-Wen
613 Points

Challenge 1

I am stuck at the challenge 1, can someone help me?

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

4 Answers

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

Hi Shih! I found that, if I didn't have the else clause, it passed the challenge but it should work either way...

def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
            break
        print(item)
def loopy(items):
    # Code goes here
    for x in items:
        print(items)
          ```
Ari Misha
Ari Misha
19,323 Points

Hiya Shih! The order of statements in a loop matters. The first statement gets executed first and followed by second statement and so on. Lets relate to this logic in the challenge. Unless your loop prints out every "item" alias in the loop , how else is it gonna get to "STOP" keyword in "items" argument. I mean it makes sense right? In your "for" loop, remove the "else" conditional first. Secondly, put print(item) statement on top, inside the loop and followed by "if" statement. If you want a code for reference , i think codes submitted in comments by Francis and Alexandra are right on money. (:

Shih Kai-Wen
Shih Kai-Wen
613 Points

Thank everyone so much, I have passed it!!