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

Henry Moreno
Henry Moreno
1,086 Points

def loopy(items): if == 'a' print(items) def loopy(items): if != 'a' print(items)

I am on .several months on this tutorial and I do not kow it it is the interface or not but I cannot get pass this simple function ...I get errors every friggin time.

breaks.py
def loopy(items): if == 'a' print(items)  

5 Answers

Ben Reynolds
Ben Reynolds
35,170 Points
  1. The code inside a function needs to start on the next line after the colon and needs to be indented:
def loopy(items):
    # code starts here
  1. You'll need a for loop to iterate through each item in items
  2. Inside the loop, check each item to see if it begins with 'a'. You'll need an if/else for this so the loop knows whether to continue to the next item, or print it. To see if the item begins with 'a' check the character at index 0. You can get the index of something with square brackets:
first_letter = some_word[0]

In the end your logic should look something like this:

def loopy(items):
    # for each item in items:
        #if the first letter of the current item is a:
            #continue
        #else:
            # print the item
Henry Moreno
Henry Moreno
1,086 Points

Thanks a ton ...that was expertly put and a great answer .!!! I asked this question months ago.. bottomline you deserve good credit for your answer. Thanks again. Henry

Ben Reynolds
Ben Reynolds
35,170 Points

Thanks Henry, glad to help! Consider hitting the old up-vote button if you feel it was helpful. Happy coding and good luck!

Marzoog AlGhazwi
Marzoog AlGhazwi
15,796 Points

what's wrong with my code

I get Didn't find the right items being printed

def loopy(items):
    for word in items:
        if items[0] == "a":
            continue
        else:
             print(items)
Jonathan Beard
Jonathan Beard
1,681 Points

You are iterating through with the items rather than the word.

if word[0] == 'a':