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

Break function

I am working on the breaks.py challenge, and I've been working on it for the last two days but just can't seem to figure it out.

What can I do to fix this? I tried using external sources to help solve it but nothing has worked so far. Thank you!

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

5 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

your if block is under the for loop, not in it. it needs to be tabbed over once to be inside. then, i think it wants you to check if the item is stop before printing, so that if it is stop, it doesn't print stop.

Thank you for your quick reply! james south . How would I go about the second part?

Nthulane Makgato
PLUS
Nthulane Makgato
Courses Plus Student 19,602 Points

Jame is right.

For the second part:

  1. You have to check that your conditions for "break" are just after the for loop and before you print each item.

  2. Ensure that that BOTH print and "if statement are in the for loop, not outside it. Right now, your if statement is outside the for loop

for item in items:
      if item ==...
           break
      print...

Ellipses dots are for structure, you can fill in the rest.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

?? that is the second part. are you talking about the next challenge, using the continue keyword? for that one use slice notation with the square brackets [].

Thank you guys for the help! It was correct. james south Nthulane Makgato