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 trialsonam rathore
703 Pointswhat is wrong with the challenge task 2 of 2 of shopping list?
what is wrong with this code?
def loopy(items):
if item=='STOP':
break
for item in items:
print(item)
2 Answers
Jacob Herrington
15,835 PointsHey Sonam, you've got all the right components -- so good job there! The problem is how you've got them laid out. It usually helps me to think it out as an algorithm before really coding.
So for this challenge:
# Loop through the items array
# If an element has the value "STOP" break the loop
# Otherwise print the element
The next step for me is to begin turn that algorithm into code. In Python, we need to be careful to do this in the right order so that we keep our indentation right.
def loopy(items):
# Loop through the items array
for item in items:
# If an element has the value "STOP" break the loop
if item == "STOP":
break
# Otherwise print the element
else:
print(item)
Does this make sense to you?
sonam rathore
703 Pointshi jacob. thanks for such a good explaination. its a very good method that you follow. it will help me to solve the remaining task challenge.
Alexander Davison
65,469 PointsCan you give best a Best Answer
to Jacob Herrington so that this question will be seen by people in the Community as an answered question? Thank you! ~alex
Jacob Herrington
15,835 PointsSure thing -- this helps a lot when you get complicated decision structures.