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 trialmarvelousstudent317
Python Web Development Techdegree Student 1,237 PointsI need help
i don't know what I have done wrong in my code
def loopy(items):
# Code goes here
for item in items:
print(item)
item == "STOP":
break
1 Answer
William Li
Courses Plus Student 26,868 PointsYou need to use the if...else clause here; also, the condition check goes before print(item)
, and only output item if the condition check fails.
def loopy(items):
# Code goes here
for item in items:
if item=='STOP': # condition check for whether item == 'STOP'
break # if so break out of the loop
else: # otherwise
print(item) # output item
hope it helps.
A X
12,842 PointsA X
12,842 PointsWhat part of the code challenge are you referencing with your code? There's 2 parts to this challenge.