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 trialDavid Gabriel
Python Web Development Techdegree Student 979 Pointsfor loop
Hi all,
Can you please help with my error below: def loopy(items): # for item in items for item in items: if item("items") == "stop": break else: print(item)
def loopy(items):
# for item in items
for item in items:
if item("items") == "stop":
break
else:
print(item)
1 Answer
AJ Salmon
5,675 PointsHi David! There are a couple problems here, the first one being your syntax in your 'if'. You don't need to have ("items") after the word item, because you already clarified that your for loop is being performed on the argument 'items'. Also, loop variables don't work like that, for the same reason. The second issue is that the challenge asks for you to break the loop when the string "STOP" is passed to the function, and you had it break for the string "stop". While they're the same word, they are different strings, due to the case of the letters. It should look something like this:
def loopy(items):
for item in items:
if item == "STOP":
break
else:
print(item)
Hope this helps!
David Gabriel
Python Web Development Techdegree Student 979 PointsDavid Gabriel
Python Web Development Techdegree Student 979 PointsThank you very much AJ
Steven Parker
231,271 PointsSteven Parker
231,271 PointsFYI: The "else" isn't needed because of the "break" (but it doesn't hurt).
AJ Salmon
5,675 PointsAJ Salmon
5,675 PointsAh, that thought hadn't crossed my mind, but it does make sense. Thanks!