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

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

How am I messing it?

:(

breaks.py
def loopy(items):
    # Code goes here
    for code in items:
        print(items)
            if items == "STOP"
                break
Sara Watson
Sara Watson
Courses Plus Student 3,713 Points

You have a couple of issues here. Here are some clues that may help you:
1) Have another look at your indentations. 2) Take a look at your conditional statement, it may be missing something.

8 Answers

The code doesn't pass, Sara. I tested it. Did you test it before saying it worked?

The print statement should be in the if condition's else.

Passing code:

def loopy(items):
    for item in items:
        if item == "STOP":
            break
        else:
            print(item)
Sara Watson
Sara Watson
Courses Plus Student 3,713 Points

Yes, of course I tested it. The result said "Well done" and then continued.

:warning: It passes the first task, but it doesn't pass the second task. Yusuf is on the second task.

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

I noticed I need a colon after the if statement but I'm lost when it comes to indentation, are they any hard and fast rules in regard to that?

Sara Watson
Sara Watson
Courses Plus Student 3,713 Points

Python is structured so that your indents create blocks of code. The first block begins after the function name, where it says # code goes here. All code should line up with that indent. When you have a loop or a conditional statement, you indent to create new blocks of code. It indicates that the new code belongs to that loop or that condition. In your code you have a conditional statement that really belongs to the for loop, but you have it nested under print.

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

Sara this is what my code looks like now def loopy(items): # Code goes here for code in items: if items == "STOP": break print(items)

I don't understand what the indenting issue is here?

Sara Watson
Sara Watson
Courses Plus Student 3,713 Points

Your print(items) was actually fine where it was. Both the print and the conditional if statement should be indented and lined up under the for loop. Make sure you are using the same number of indent spaces whenever you indent. So if you are indenting 4 space, they should both be indented 4 spaces under the for loop.

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

I have updated my code to look like this def loopy(items): # Code goes here for code in items: print(items)
if items == "STOP": break

But still have an error :(

Sara Watson
PLUS
Sara Watson
Courses Plus Student 3,713 Points
def loopy(items):
    # Code goes here
    for code in items:
        print(items)
        if items == "STOP":
            break
Yusuf Cattaneo
Yusuf Cattaneo
522 Points

I literally copy and pasted your code and it wont pass

Sara Watson
Sara Watson
Courses Plus Student 3,713 Points

Yes, the code does pass. That is the answer. Make sure you are in the correct challenge and task.

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

Yeah it only passes the first task not the second one

Sara Watson
PLUS
Sara Watson
Courses Plus Student 3,713 Points

Sorry, my bad. I was only addressing the first task.