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

Question 2

Hi, I am a complete novice at coding and I am stuck on this problem. I can figure out what I am doing wrong with question two. Can someone please explain what I am doing wrong? Here is the code that I have done and from everything, I can find on Google it seems to be right but I keep getting the error message saying that it is wrong.

def loopy(items): for item in items: print(item)

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

        if item == "STOP":
            break

1 Answer

andren
andren
28,538 Points

The code itself is fine. The issue is that even though it is not explicitly stated the task expects the loop to exit the second the STOP item is encountered, in other words the if check is meant to be placed before the print function.

So if you move them around like this:

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

Then the code will work.

Thank you so much andren. That has helped me out something shocking.