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

breaks.py Exercise: Skipping the List item in for loop

Hi Andreas, Thanks for the response. As you said I interpreted this question the same way first time and wrote the code as below. But even this won't work.

breaks.py
def loopy(items):
    # Code goes here
  if items[0] == 'a':
    items.remove('a')
  for no in items:
    print(no)

3 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

The if statement should be inside the loop. If the current item in the loop starts with "a" then you ignore it and continue to the next item. Otherwise, you will print it:

def loopy(items):
  for item in items:
    if item[0] == "a":
      continue
    else:
      print(item)

i fixed with :

item == "STOP"

print (item)

thnks

Kourosh Raeen
Kourosh Raeen
23,733 Points

Still not right. I'm not sure why you're using the string "STOP". You need to check to see if the current item's index 0 is the letter "a". If it is you skip it using the continue keyword, otherwise you print it.

def loopy(items): for item in items: if item == 'STOP': break else: print item

Kourosh Raeen
Kourosh Raeen
23,733 Points

This is not the right solution.