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 trialIshan Rahman
2,155 PointsCan't seem to get the second challenge
Whats wrong with the code?
def loopy(items):
# Code goes here
if items == 'STOP':
break
for items in items:
print (items)
1 Answer
Torsten Lundahl
2,570 PointsThe challange want you to check every item in items to see if it equals to 'STOP', and in that case break the loop. Place the if statement inside of the loop to check every item that's being iterated.
for item in items:
if item == 'STOP':
break
print(item)
Also it's a good habit not to use the same name on two variables, especially in the same section of code. It doesn't seem to cause any errors in this example, but it's a good thing to have in mind when programming.
for items in items:
#change to
for item in items:
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 PointsModerator Note, changed this from comment to answer. If you come up w/ a hint/solution to the question, it's best to post 'em as answer so your writeup may receive credited from getting marked as Best Answer, this also serves as a way of letting other students in the forum know that the question has been solved. Thanks for helping out & happy coding.