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

My first part of this code challenge is correct, I don't understand what's wrong in the second part?

When I copy the exact same code and then paste in the python shell everything is fine. But in code challenge it keep showing Try Again.

Here is my code:

def loopy(items):
    # Code goes here
    for something in items:
        print(something)
        if something == 'STOP':
            break
breaks.py
def loopy(items):
    # Code goes here
    for something in items:
        print(something)
        if something == 'STOP':
            break
Bapi Roy
Bapi Roy
14,237 Points

You need to post, what is said to you to do. Otherwise is hard to guess what is wrong.

Hey You can click on the "View Challenge" to go to the code challenge page there you can see what is the challenge. "View Challenge" is on the top right side .

Bapi Roy
Bapi Roy
14,237 Points

Here is correct code

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

        print(something)

You don not need to print STOP

Thanks Bapi Roy for help.

1 Answer

Steven Parker
Steven Parker
231,248 Points

:warning: Be careful about testing a challenge in an external REPL.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, your code is printing first before it checks the word., so STOP will be printed. But if you do the check before the print, your code will be able to stop first.

Thanks for this advice, I got it.