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 trialRyne Ziemba
9,967 PointsBreak loop problem
Why is this code not working to break the loop? I replace item for words and neither one works. Thanks!
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(items)
2 Answers
Alexander Davison
65,469 PointsYou weren't asked to print the actual list; you were asked to print each individual item in the list.
Try using the noun item
instead of the plural noun items
.
Like this:
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
# Fixed! :)
print(item)
Good luck! ~alex
Ryne Ziemba
9,967 PointsHmmm. I tried that but it still says "Bummer! Try again!"
Alexander Davison
65,469 PointsWhat's the challenge's question?
Kenneth Love
Treehouse Guest TeacherI tried this solution and it worked for me (typed it myself, though, not copy/paste). Are you still getting the bummer message? Can you try refreshing the challenge and submitting this code again?
Ryne Ziemba
9,967 Pointsit is this "Oops, I forgot that I need to break out of the loop when the current item is the string "STOP". Help me add that code!"
The prior challenge is "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!" which I solved correctly with:
def loopy(items): # Code goes here for word in items: print(items)
Alexander Davison
65,469 PointsI'm 99% sure that your code is right. I've been looking for errors in your code for 20 minutes now. I think the challenge has some bug...
Tagging Kenneth Love
Kenneth Love
Treehouse Guest TeacherWhy are you printing items
instead of each individual item, which in your code would be word
?
Alexander Davison
65,469 PointsI already fixed that in my script.
Ryne Ziemba
9,967 PointsRyne Ziemba
9,967 Points*or "word", rather, not "words"