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 trialGregory Johnson
3,367 PointsI'm not too sure about how to write this if statement correctly
I'm olmost there but not sure how to use index to find the "a" and then ignore and print out everything but the a
def loopy(items):
# Code goes here
for item in items:
if item == item.index(0) = "a":
break
print(item)
2 Answers
Duy Pham
Courses Plus Student 44,614 PointsYes Gregory! continue statement is used to skip an element and move to the next part of the loop. So in this case, it will skip "a" (means not printing letter "a") and move to the next one.
Duy Pham
Courses Plus Student 44,614 PointsHi there,
The Problem: Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. 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. Example: ["abc", "xyz"] will just print "xyz".
The problem is asking you to move on to the next one if the character at index 0 is "a". To skip an element and move on, you must use continue statement instead of break. Break statement is used to break out of the loop. So you code should be like this:
def loopy(items):
for item in items:
if item[0] == "a":
continue
print(item)
Gregory Johnson
3,367 Pointsso this statemant pretty much says if the first item in item is an a, continue to next to the next part of the loop without "a"....I'm trying to figure out what's telling python not to write "a"