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 trialWilfredo Casas
Courses Plus Student 523 PointsWhat is wrong with my code?
I am following the instructions, but it tells me "Try again"
def loopy(items):
# Code goes here
if items[0] = "a":
continue
for i in items:
print(i)
2 Answers
Keli'i Martin
8,227 PointsYour 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!
James Gill
Courses Plus Student 34,936 PointsKeli'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".
Wilfredo Casas
Courses Plus Student 523 PointsWilfredo Casas
Courses Plus Student 523 PointsThanks, 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
8,227 PointsKeli'i Martin
8,227 PointsSo if we assume that the
items
here are the same as in the shopping list app, then we know that eachitem
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 stringapples
as an array of letters. It would look sort of like this:Looking at it like this, you can see that
item[0]
would refer to the charactera
.Hope that cleared things up a little better for you!