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 trialGreg Isaacson
Courses Plus Student 702 PointsPlease help:)
Hi all...
Not sure what I am doing wrong.
I want to make a condition that if items == "STOP" then it breaks??
Thanks
def loopy(items):
for item in items:
print(items)
if items == "STOP":
break#
2 Answers
Stuart Wright
41,120 PointsNote that in your code 'items' refers to the entire list, and 'item' refers to the current item as you iterate through the list.
You are asked to print the current item and break if the current item is equal to 'STOP', but currently you are printing the entire list, and breaking if the entire list is equal to 'STOP', which will never be the case.
Stuart Wright
41,120 PointsHi Greg - I think the exercise might want you to put the condition before the print statement, so check to see if item = 'STOP' first, break if so, and if not print the item.
Greg Isaacson
Courses Plus Student 702 PointsGreg Isaacson
Courses Plus Student 702 PointsHi Stuart,
I changed my code to this:
def loopy(items): for item in items: print(item) if item == 'STOP': break
It is still failing?