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 trialHector Carrillo
934 Pointsneed to understand where to put index at for the letter a being at index 0 also if the elif statement is even needed.
kinda getting lost completely dont know if im missing something or missing alot of information. to use index to skip 'a'
def loopy(items):
for item in items
if index[0] = 'a'
break
elif
continue
4 Answers
Alexander Davison
65,469 PointsDon't give up! You'r well on your way!
Your code is almost complete! However, there are a few minor problems. If you aren't able to solve this on your own with these hints, please reply!
- Your are missing a lot of colons. For example, at the end of
for item in items
andif index[0] = 'a'
there should be colons. If you don't know what a colon is, it's this character::
- You need indentation (basically meaning spacing before statements). Since Python doesn't use things like {} to represent blocks of code, you must indent to tell Python "This code is 'inside' this code, like a for loop, for example!". This is why spacing is very important in Python.
- You shouldn't use
elif
.elif
is used to chain conditions whileelse
is used to do something if theif
statement's condition isn'tTrue
.elif
is similar toelse
, but it is run if theif
isn't run, and theelif
satisfies another condition! Think ofelif
as "else, if". It makes more sense that way - You can't use just one
=
to test if one value is equal to another. If you use that, Python will think you are assigning a variable calleda[0]
to the value'a'
. I'm not kidding. To tell Python to test if one value is equal to another, you must use the double equals operator. It look like this (with two equal signs):==
- You need to
print
theitem
if the first letter in theitem
isn't the letter 'a'. Read the instructions! - The variable
index
inindex[0]
isn't a variable you created, so Python doesn't know what to do withindex
. Did you mean to sayitem
instead?
I hope these hints help.
~Alex
EDITED: Realized there was more errors in your code, updated my post
EDITED 2: Realized there was the index[0]
thing which is also causing an error. Thanks Lucas Frischmann
for noticing this!
Lucas Frischmann
1,397 PointsHey guys,
I've few questions. Why is there index[0] and not items[0]? Why should we print items and not item?
Sorry it's maybe a newbie question :/
Alexander Davison
65,469 PointsNo, good catch!
I didn't see that. You found another error
Congrats on spotting that!
Apparently the code for the question (the code Hector Carrillo wrote) is very buggy
Robert Bryan
2,869 PointsI am having similar issues with the same problem. Not sure how to translate the directions into code and getting "Bummer Try again!" does not give me any clues.
def loopy(items):
for item in items:
if index[0] == 'a':
continue
else:
print(items)
Thank you for the help...
Alexander Davison
65,469 PointsYou are extremely close. All that is wrong is the indentation.
You don't use {}
to represent blocks (like in JavaScript you use {} to represent blocks) in Python, so indentation is important!
Add four more spaces to the beginning of each of the last three lines of code and you should watch your code pass
Also, use the variable item
instead of index
where you are doing index[0]
. index
isn't a variable you created so Python will throw an error because it doesn't know what index
is!
~Alex
slavster
1,551 PointsAlexander Davison is mostly correct, you just need to make one tiny change to the last line of code.
The instructions indicate that it should print ONLY the items from the list which do NOT begin with "a". Your last line of code is saying, "print the entire list", which is not the same. You're almost there though!
Robert Bryan
2,869 PointsI think I have everything except for the print items that do not begin with "a".
def loopy(items):
for item in items:
if item[0] == 'a':
continue
else:
if item[0] != 'a':
print(items)
Alexander Davison
65,469 PointsOk, your code is not working because you didn't indent this line enough:
print(items)
Python is very picky abut indentation, so you'll need to add an extra 4 spaces before it.
You either can indent, as I said above, or you can remove the if item[0] != 'a'
completely. This is because if the first if condition if item[0] == 'a'
is not True
, then the else
clause is run. So to make your code cleaner, you can just remove the line completely.