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 trialstevenhohberg
12,328 PointsPython Basics
I am having trouble solving this question can someone please explain me what i should do ? my original code is
def loopy(items): for item in items: if items.index(0) == "a": continue else: print(item)
def loopy(items):
# Code goes here
2 Answers
Žiga Pregelj
18,126 PointsYou're almost there, only change continue with pass and it will work ;)
def loopy(items):
# Code goes here
for item in items:
if item[0] == "a":
pass
else:
print(item)
Oh, and you can choose first index only with these brackets and number inside [0], but it should work with your way too.
Žiga Pregelj
18,126 PointsI checked it out and you have to use CONTINUE in this case, because PASS doesn't do nothing, it just checks the first item's index and goes on to else, while continue makes that loop go through all items and checks if their first letter is "a".
I think that this challenge shouldn't work with pass, maybe Kenneth forgot to turn off this option :D .
Here is a little bit deeper explanation:
And code with continue
def loopy(items):
# Code goes here
for item in items:
if item[0] == "a":
continue
else:
print(item)
stevenhohberg
12,328 Pointsstevenhohberg
12,328 PointsHey thanks for the help. I found it a bit hard to understand the difference between pass and continue cause i tested it out and it gives back the same results. What i understood is that continue only works in a for or while loop, and pass works in a more general purpose. If you could provide me some examples would be great.