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 trialKade Carlson
5,928 PointsWhat did i do wrong here?
Can someone please explain to me what I did wrong?
def loopy(items):
for item in items:
if item[0] == "a":
continue
print(item)
4 Answers
Thomas Fildes
22,687 PointsHi Kade,
Please see the code below that I used to pass this challenge:
def loopy(items):
# Code goes here
for item in items:
if item[0] == "a":
continue
else:
print(item)
It looks like you are only missing the else statement.
Hope this helps! Happy Coding!!!
Jennifer Nordell
Treehouse TeacherHi there, Kade! You're doing terrific! Please note that I have some comments regarding the answers you've received thus far. First, you can use continue
in any kind of loop or with an if statement. And that's what I used for this challenge. Secondly, you do not need the "negative" or not operator for this. Third, you do not necessarily need an else
statement.
The only problem with your code is indentation. You've put the print statement outside the for loop. So item
is now out of "scope". The variable item
is a temporary variable that only exists while that for loop is executing. Once the for loop completes execution, that variable disappears. So, if I indent your print statement to be inline with the if
statement, your code passes with flying colors! Take a look:
def loopy(items):
for item in items:
if item[0] == "a":
continue
print(item)
Hope this helps, and keep coding!
Blayne Holland
19,321 Pointsunless each "item" is an array nothing is going to print out because the index of 0 does not exist.
Also the print() statement isn't in the for loop block so you might also get an error saying the variable does not exist.
Brecht Philips
8,863 PointsTry the negative if item [0] != 'a' Print item
Continue is typically used with a while loop not in an if statement
Jay Norris
14,824 PointsJay Norris
14,824 PointsYou aren't "printing the current member", maybe with an else in the loop.