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

Santosh Lalwani
Santosh Lalwani
873 Points

loopy function

i ran the same code in cloud based Python editor it works. What is the issue here. the continue is actually taking the value of the "items" and not printing if the first element is "a"

breaks.py
def loopy(items):
    # Code goes here
    for i in range(len(items)):
        if items[i]=="a":
            continue
        else:
            print(items[i])

1 Answer

Hey there. You do have the right idea, but alot of the time, the code challenges are specific in how they want the problem solved. That said, there are a few discrepancies.

You won't need to call 'for i in range(len(items))'. That's essentially saying for an item in the length of the word items.

On your if statement, you need to call 'i' in that code, rather than 'items', and your [i] should actually be [0], as that is the index they're looking for.

Lastly, you would need to print the specific one that caused the else to occur.

def loopy(items):
    # Code goes here
    for item in items:
        if item[0]=="a":
            continue
        else:
            print(item)

Try something like this.