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 trialAndrew Heggie
6,348 PointsQuestion 2
Hi, I am a complete novice at coding and I am stuck on this problem. I can figure out what I am doing wrong with question two. Can someone please explain what I am doing wrong? Here is the code that I have done and from everything, I can find on Google it seems to be right but I keep getting the error message saying that it is wrong.
def loopy(items): for item in items: print(item)
if item == "STOP":
break
def loopy(items):
for item in items:
print(item)
if item == "STOP":
break
1 Answer
andren
28,558 PointsThe code itself is fine. The issue is that even though it is not explicitly stated the task expects the loop to exit the second the STOP item is encountered, in other words the if
check is meant to be placed before the print
function.
So if you move them around like this:
def loopy(items):
for item in items:
if item == "STOP":
break
print(item)
Then the code will work.
Andrew Heggie
6,348 PointsAndrew Heggie
6,348 PointsThank you so much andren. That has helped me out something shocking.