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 trial

Python Python Basics (2015) Shopping List App Continue

Trevor Wood
Trevor Wood
17,828 Points

I don't understand why this didn't work

So I finally got this code challenge after googling a bit. But I don't see why my original code didn't work.

# Original
def loopy(items):
    # Code goes here
    for item in items:
      if item.index("a") == 0:
        continue
      else:
        print(item)


# Passed code
def loopy(items):
    # Code goes here
    for item in items:
      if item.startswith("a"):
        continue
      else:
        print(item)

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Because the index() method throws a "ValueError: substring not found" error if the item doesn't contain the letter a, whereas the startswith() method returns False.

It's as @kourosh said: your failing method returns an error, but your passing method returns a boolean (True or False). The failing method can't "continue".