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

Aiden Colley
Aiden Colley
926 Points

Not sure why I keep getting it wrong...

Hello, my code challenge wants me to beak the loop when it hits 'stop' but I checked my code and I didn't see anything wrong.

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        print(items)

        if item == 'STOP':
            break

4 Answers

Ben Reynolds
Ben Reynolds
35,170 Points
  1. Check if the item equals 'STOP' before the print statement. If it does, it should hit the break statement before attempting to print.
  2. In the print statement, print the current item instead of the whole list (item vs items)
Aiden Colley
Aiden Colley
926 Points

sorry for not replying sooner, I tried what you did but it didn't seem to work.

Ben Reynolds
Ben Reynolds
35,170 Points

Can you share the latest version of your code?

Ben Reynolds
Ben Reynolds
35,170 Points

A link to the exercise will only show me the default starter code, not the code you've written. Here's the format to go for:

def loopy(items):
    for item in items:
        # if item text is 'STOP'
            break
        # print current item (this line will only be reached if break wasn't hit, so no need for an else block)
Aiden Colley
Aiden Colley
926 Points

Thanks! I figured it out:)