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 trialYusuf Gillani
Python Web Development Techdegree Student 3,643 PointsThis is still not working for me :(
Can someone tell me what I'm doing wrong? I've put the if statement inside the loop.
def loopy(items):
for item in items:
if item == "STOP":
break
1 Answer
AJ Salmon
5,675 PointsYour if statement is correct! The issue is that the function is still supposed to print any items that come before 'STOP'. Here's an example of what the output should be for two similar lists:
>>> list1 = ['apple', 3, True, 'Star Wars']
>>> loopy(list1)
apple
3
True
Star Wars
>>> list2 = ['apple', 3, 'STOP', True, 'Star Wars']
>>> loopy(list2)
apple
3
Because there was no 'STOP' string in list1
, all of the items were printed. The for loop broke when it got to the end of the list. When loopy is passed list2
as the argument, it prints all of the items that come before 'STOP'
. All you need to do is make sure your function is still printing the items it's given! Hope this helps