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 trialEdgar Jin
10,747 PointsLoopy items. I tried all the code here, not working.
I tried all the code on the board, but none of them worked for me. I really do not understand what is the real problem. Maybe error? Please let me know how to pass this chapter. Below is my code, but not passing
def loopy(items): # Code goes here for item in items: if item == "STOP": break print(item)
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(item)
3 Answers
andren
28,558 PointsThere are two tasks in this challenge. The code you have posted is correct for task 2, but not for task 1. In task 1 you are just meant to print out the items, like this:
def loopy(items):
# Code goes here
for item in items:
print(item)
Once you get to task 2 you can paste in this code:
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(item)
And it should work.
Amitesh Singh Baghel
2,256 PointsThe print(item) line will come in else loop. The if loop only checks for "STOP", when it finds it in items, the loop breaks. If it doesn't find it and u want it to do something, then for that you will need else loop. So, write else: and inside that put print(item) to show the items. So, the first the if loop is checked if it doesn't find stop, the condition fails and it goes into else loop and print item.
Edgar Jin
10,747 PointsThanks everyone, it was very helpful :)