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 trialkhabir baukman
436 Pointscan someone tell me where i went wrong
i dont see why its telling im printing the wrong thing
def loopy(items):
for a in items:
if items == "Stop":
break
else:
print (items)# Code goes here
1 Answer
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsThere are a few mistakes in your code:
I see you're saying for a in items and this is working, but it would be a little more readable (in larger scripts) if you try to give variables names that makes sense i.e. for item in items
def loopy(items):
for a in items:
if a == "STOP": # because in a loop you want to check 'a' and not 'items'
break
print(a) # you don't need the else statement + you want to print 'a' instead of 'items'
# changed 'a' to 'item' to show how it makes it more readable
def loopy(items):
for item in items:
if item == "STOP":
break
print(item)