Shopping list Task
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".
I have written the following code but gives me wrong answer, pls help me in understanding this
def loopy(items): # Code goes here items = ["abc","xyz"] for letter in items = a: continue else: print "items
Hey CH! Couple of things here. The variable items is is already defined, and will be sent to the function when you "check answer" therefor you do not need to define it yourself. Secondly you have some issues in your for loop. To outline, we simply want to loop thru every item in the list "items" and check if the current item has an "a" at index 0. Ill provide the correct code to demonstrate this:
def loopy(items): #Here the items list is already defined. for i in items: #This will loop thru every item in the list "items" and assign current item to the variable "i" if i == "a": #Checking if the index 0 of the current item is the same as the string a continue #If this is the case, just coninue to the next item, but dont do anything. else: #If this is not the case however, print the item print(i)