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 trialEric Marangu
Python Web Development Techdegree Student 730 Pointsfor loop break statement now working
I have written the code attached but can't get what's wrong with it. Please help
def loopy(items):
# Code goes here
for item in items:
print(items)
if item == 'STOP':
break
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! First, you're doing great, but let's translate your code to English and see what it says:
For every individual item in the items list:
print the entire items list
If the individual item is STOP:
stop the loop
This means that every time you get to a new item, you don't print the item
but rather the entire list. Above and beyond that, you will also be printing out "STOP". Let's imagine that your list contains ["bread", "butter", "cheese", "STOP"]. You should first check to see if it is stop and if it is, break from the loop. Otherwise, it will print out stop and then break.
I think you can get it with these hints, but let me know if you're still stuck!
Eric Marangu
Python Web Development Techdegree Student 730 PointsEric Marangu
Python Web Development Techdegree Student 730 PointsThank you Jennifer, i'm going to have a go at it again using your hints if i get stuck... i'll be back!
Eric Marangu
Python Web Development Techdegree Student 730 PointsEric Marangu
Python Web Development Techdegree Student 730 PointsHI Jennifer,
Can't seem to make this work. please help :-)
I'm missing something