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

Rinze Winters
Rinze Winters
4,932 Points

Where is the wrong?

Can't figure out what is expected from me in the following assignment https://teamtreehouse.com/library/python-basics/shopping-list-app/continue

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
            break
        elif item == "a": 
            continue
        print(item)

1 Answer

Hi, Maybe it helps to get an idea of what you are looping through? So I added something that might help in the code but don't add it in the challenge. It will loop through the different words and if it has an 'a' in the first index, it will skip this and not print it. Below example will only print 'pear' and ' chair'. The 'a' is at index 0 for the other two.

Hope this helps :)

items = ['apple', 'pear', 'chair', 'ant']

# This is the code below
def loopy(items):
    # Code goes here
    for thing in items:
        if thing[0] == 'a':    # If the index at 0 is equal to a then it will continue to next word
            continue
        else:    # any other word will print
            print(thing)

# if you are able to copy into workspaces this will run the function to see it work
loopy(items)
Rinze Winters
Rinze Winters
4,932 Points

Thank you Chris! Now I understand the content of the assignment.