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

What is wrong with my code?

I am following the instructions, but it tells me "Try again"

breaks.py
def loopy(items):
    # Code goes here
    if items[0] = "a":
      continue
    for i in items:
      print(i)

2 Answers

Keli'i Martin
Keli'i Martin
8,227 Points

Your code is checking to see if the items index 0 is equal to "a". What you really want to check for is the item inside of items and see if that item index 0 is equal to "a". So your code would look something like this:

for item in items:
    if item[0] == "a":
        continue
    print(item)

Hope this helps!

Thanks, but I do not understand very well, how could item have a [0], I thought only lists like items had an index

Keli'i Martin
Keli'i Martin
8,227 Points

So if we assume that the items here are the same as in the shopping list app, then we know that each item is just a string (ie. apples, a new car, etc). And a string is nothing more than an array of characters. So we are able to access each letter in the string the same way we would access an item in a list of items. Think of the string apples as an array of letters. It would look sort of like this:

a -> item[0]
p -> item[1]
p -> item[2]
l -> item[3]
e -> item[4]
s -> item[5]

Looking at it like this, you can see that item[0] would refer to the character a.

Hope that cleared things up a little better for you!

Keli'i Martin got it right. Think of it this way: You need a loop ("for x in y") to evaluate something--to iterate over each item and see if it passes a test before you do something. That means all the "testing" code and the "do something" code go inside that loop.

In this case, the test is "is the first character 'a'? If so, continue and print all the other characters".