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 trial

Python Python Basics (2015) Shopping List App Continue

CHENG HAO.HSUAN
CHENG HAO.HSUAN
663 Points

I 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.

breaks.py
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)

Hi, 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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Your 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)