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

Evan N
Evan N
3,244 Points

I don't fully understand why my program isn't actually printing the values up until "a" within my console

My code passes but I am not seeing the items print up until "a"

So, my understanding is that this program loops through the items until "a" and continues through the loop without stopping. However, even if I change the list to not include "a" the program will still not print to the console.

def loopy(items):

    for item in items:
        if item[0] == "a" :
            continue
        else:
            print(item)
items = ["z", "c", "a", "d"]
breaks.py
def loopy(items):
    # Code goes here

1 Answer

andren
andren
28,558 Points

The def keyword defines a function, but it does not run any of the code within it. In order to run the function you have to call it and pass it a list to work on.

Here is an example:

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

# Call loopy with list as argument
loopy(["z", "c", "a", "d"])

That will result in:

z
c
d

Being printed out.