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 trialJason Martino
1,573 PointsI need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in item
Please help!
def loopy(items):
# Code goes here
for item in items:
print(items)
if item in items == "STOP":
break
1 Answer
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHi there Jason. There are just a couple of tweaks you need to make to your code. Firstly, you should be checking if the current item is equal to 'STOP'
before you print it. Also, if item in items
is not needed and can just be written as if item
as item
is already the current item in the list. Lastly, I have noticed you have printed items
instead of just item
. Printing items
would print out the whole list where you only want to print out that individual item.
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(item)
You could use an else block for print(item)
but it is not necessary. If you have any further questions please let me know :).
Thanks,
Haider