Python Python Basics (2015) Shopping List App Continue

siva sanka
siva sanka
4,099 Points

help me regarding this code

Same idea as the last one. My loopy function needs to skip an item this time, though.

Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member.

Example: ["abc", "xyz"] will just print "xyz".

breaks.py
def loopy(items):
    # Code goes here
    if items(0)=='a':
        continue
    else:
        print(items)

1 Answer

Hey siva! Couple of things, one is that you should loop through ever item in the list "items". You should use a for loop for this. Secondly is that your not looking at indexes correctly, when looking at an index we dont use () we use []. If you dont know for loops i recommend you rewatch the video about them, as they are quite important in just about any programming language. For your code:

def loopy(items):
    # Code goes here
    for item in items: # Here were doing a for loop which will check ever "item" in the list "items"
        if item[0]=='a': #Here were checking if the current items has the string "a" at index value 0
            continue
        else:
            print(item) #Here were printing the item, you dont want to print the entire list "items", just the item