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 trialKennedy Otwenyo
785 PointsWhat am I missing?
I have edited the code but I am still getting the same response "Didn't get the right items to print"
def loopy(items):
for item in items:
if items[0]=="a":
continue
else:
print(item)
3 Answers
Alexander Davison
65,469 PointsYes, you are very close. In this answer, I'm basically saying the same thing as Jason Anello.
Jason said clearly that:
The challenge is asking you to check index 0 of the current item that you're looping over. You're checking index 0 of the items argument that was passed in.
I am going to simplify this to be easier to understand.
Look at this line of code you've written:
if items[0] == "a":
Note: I modified it a little to look prettier, but it does the same thing.
Now, let's read what the challenge wants: (I copied this directly from the code challenge.)
Loop through each item in items. 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.
Okay, now let's look at what your code is doing: (I wrote this myself.)
Loop through each item in
items
. If the very first element in theitems
list is the lettera
, don't print the element.
You see the difference? For the first example, the loop goes through every element in the list. If the current element has the letter a
, don't print the element, else print the element.
In your code, it won't print anything if the first element in the list is "a"
.
Check the first element of the "temporary variable" (in your code it's called item
) instead of the list the loop is iterating through and you should pass
I hope this helps
If this doesn't help, reply with your second attempt's code and I'll try to help more.
~Alex
Jason Anello
Courses Plus Student 94,610 PointsHi Kennedy,
The challenge is asking you to check index 0 of the current item that you're looping over.
You're checking index 0 of the items
argument that was passed in.
Alexander Davison
65,469 PointsI don't see how this answer is down-voted, since Jason Anello clearly explains how the code is wrong.
Don't expect anybody to give you answers to challenges straight. If you just give an answer without an explanation, the person asking the question can just copy-and-paste the passing code and don't even know what's wrong in their own code.
The best way to learn programming is to try to challenge yourself. If you got the answer from somebody else, you aren't challenging yourself.
Kennedy Otwenyo
785 PointsHi Guys, Thank you all for the input, I now see my error. I also appreciate the approach of explaining the answer as stated by Alexander rather than solving the problem. I do agree this approach has encouraged me to understand and even learn further. Good looking out!