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 trialAnusha Singh
Courses Plus Student 22,106 PointsPlease help
I just can't figure out that what is the mistake which I made in this code. The question is : 'Oops, I forgot that I will need to break out of the loop when the current item is on "STOP". Help me add that code! ' Now I can't figure out the mistake in the code which I have written below. Please find out the mistake and tell me if possible - A.S.A.P
def loopy(items):
# Code goes here
for word in items:
print(word)
if word == "STOP":
break
1 Answer
Philip Gales
15,193 PointsThey want you to not print the word (break out of the loop) if the word is STOP. You printed the word and then broke the loop.
def loopy(items):
# Code goes here
for word in items:
if word == "STOP":
break
print(word)