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 trialCoffee Li
Courses Plus Student 2,229 Pointswhat is wrong with my breaks.py
def loopy(items): # Code goes here for item in items: print item
def loopy(items):
# Code goes here
for item in items:
print item
if item == "STOP":
break
8 Answers
Rich Zimmerman
24,063 PointsYou just need to have it print item AFTER the conditional check for "STOP", this way "STOP" isn't printed.
Coffee Li
Courses Plus Student 2,229 Pointsstill not work:
def loopy(items): # Code goes here for item in items: if item == "STOP": break print item
Rich Zimmerman
24,063 PointsMake sure your print line is not indented with the break.
def loopy(items):
for item in items:
if item == "STOP":
break
print(item)
Indentation is very important with python
Coffee Li
Courses Plus Student 2,229 PointsMY print line is not indented with the break, just checked one .more time.
Coffee Li
Courses Plus Student 2,229 Pointsit however can't get through , even though i copy and paste your code above
Coffee Li
Courses Plus Student 2,229 PointsAlso , I really cann't see any needs for "STOP", didn't understand why we need a condition to very == "STOP"
Coffee Li
Courses Plus Student 2,229 PointsChallenge Task 1 of 2
I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items. Reminder: Check your syntax and indenting!
is there any sign of requiring a "STOP" conditional check?
Rich Zimmerman
24,063 PointsI'm not sure then, there must be an error somewhere because my code works for the challenge. Double check your spacing or maybe you're missing a semi-colon or something.
The conditional check for "STOP" is in Task 2 of the challenge.
Coffee Li
Courses Plus Student 2,229 PointsHi Rich, Can you help paste ur code here ? Thanks so much
Rich Zimmerman
24,063 PointsSame code as above. For task 1 you just want the loop:
def loopy(items):
for item in items:
print(item)
In task 2 you're adding the conditional statement within the loop
def loopy(items):
for item in items:
if item == "STOP":
break
print(item)
Coffee Li
Courses Plus Student 2,229 PointsThanks Rich, I got it, I add "conditional stop" a bit ahead in task 1, that is why it always failed .