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 trialCHENG HAO.HSUAN
663 PointsI don't know where am I wrong. I have this problem. Didn't find the right items being printed. How can I do?
I have this problem. Didn't find the right items being printed.
def loopy(items):
# Code goes here
for new_item in items:
if new_item == "STOP":
break
elif new_item == "a":
continue
for item in items:
print(item)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYour first for
loop will either break at a 'STOP', continue if a new_item
is exactly and "a", or continue anyway after parsing all the items. The second for
loop will simply print all the items.
The solution is to combine the two loops into one, printing as you go, but stop at a 'STOP'
def loopy(items):
for new_item in items:
# does this item start with "a"?
if new_item[0] == "a": # <-- add slide index for first char
# Yes. continue to the next item (bypass print)
continue
# If did not skip to next iteration, so print item
print(new_item)
Dan Oswalt
23,438 PointsDan Oswalt
23,438 PointsHi, make sure you're reading the question closely, you're gonna need to test the first letter of new_item for 'a', not the word itself