Python Python Basics (2015) Shopping List App Continue

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

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,166 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
11,242 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':