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 trialMakan Fofana
Courses Plus Student 1,773 PointsNeed some help with the for loop
Having trouble with this
def loopy(items):
for items in loopy:
print items
if items == "STOP":
break
# Code goes here
2 Answers
Sabrina Gardner
6,543 PointsI accidentally commented instead of answering (Sorry, I'm new to this...), so here's what worked for me:
Since loopy is just the name of the function that your setting up, you can't call loopy yet. Instead you call for item in items.
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
This worked for me. Hope it helps!
Chris Freeman
Treehouse Moderator 68,441 PointsThe current level of indentation on the if
statement is outside to for
loop and will only execute after the for
loop completes.
To fix your code, indent the if statement to match the
print statement. Also, the
print should come after the if so the loop is broken on "STOP" without printing "STOP". The
print ` statement needs parens.
def loopy(items):
for item in items:
if item == "STOP":
break
print(item)