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 trialStivan Radev
1,475 PointsI need help with this challenge
Why is my code not working?
def loopy(items):
for item in items:
print(item)
if item == 'STOP'
break
1 Answer
frankgenova
Python Web Development Techdegree Student 15,616 PointsYou have to consider the following examples: ["first_thing", "second_thing", "STOP", "another_thing"]. Would your code print the word "STOP", would your code print "another_thing"? Is that how you want it to work or do you want it to stop and not print the word "STOP". Also, think about code blocks. Your for loop and your if statement are at the same level of indentation. Based on this when will it check your if statement? Think about when you want to do the checking for "STOP". These are some hints. I have not quite given you the answer because you are close you just need to think of indentation and the position of when you check for "STOP"
def loopy(items):
for item in items:
if item == "STOP:
break
else:
print(item)
frankgenova
Python Web Development Techdegree Student 15,616 Pointsfrankgenova
Python Web Development Techdegree Student 15,616 PointsYou have to consider the following examples: ["first_thing", "second_thing", "STOP", "another_thing"]. Would your code print the word "STOP", would your code print "another_thing"? Is that how you want it to work or do you want it to stop and not print the word "STOP". Also, think about code blocks. Your for loop and your if statement are at the same level of indentation. Based on this when will it check your if statement? Think about when you want to do the checking for "STOP". These are some hints. I have not quite given you the answer because you are close you just need to think of indentation and the position of when you check for "STOP"