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 trialSeharsh Baxi
795 PointsHelp with functions
I made the loop with the break and followed the directions as asked but it is not working. Please explain what I did wrong
Directions: 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. But, if the current thing is the string "STOP", break the loop.
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
3 Answers
Julian Gutierrez
19,201 PointsThe for loop is inside the function so you need to indent everything after the first line once.
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
Jeff Hartl
Python Web Development Techdegree Student 8,420 PointsHi Seharsh,
Python is picky about indentation. At least one of your lines of code is not indented correctly.
(EDIT): Oh darn, Julian beat me to it!
Seharsh Baxi
795 PointsThe more responses, the better. Thank you a lot.
Robin *
5,670 PointsYou just messed up the indents It should be:
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
Seharsh Baxi
795 PointsI didn't know indents mattered so much in python. Thanks!
Seharsh Baxi
795 PointsSeharsh Baxi
795 PointsThank you so much!