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 trialHanifah W
395 Pointsbreaks.py assitance
here is the instructions: I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items. But, if the current thing is the string "STOP", break the loop.
Not sure what I'm not seeing?
def loopy(items):
# Code goes here
for things in items:
print(things)
if things == 'STOP':
break
loopy(items)
2 Answers
Carlos Federico Puebla Larregle
21,074 PointsYes, like like Hanifah said, you have to print every thing in items that is not "STOP", if it is you have to break the loop. Like this:
def loopy(items):
# Code goes here
for thing in items:
if thing == "STOP":
break
else:
print(thing)
I hope that helps a little bit.
Hanifah W
395 PointsThanks Jennifer. I originally had the print command with else: but it gave me a bummer. Strange. Anyway, thank you for your help with this.
Hanifah W
395 PointsHanifah W
395 Pointsfigured it out by reading other responses.
def loopy(items): # Code goes here for things in items: if things == 'STOP': break else: print(things)