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

Stuck in Continue challenge

I'm stuck on this challenge and my code doesn't work.

The challenge says this. 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".

Thanks.

breaks.py
def loopy(items):
    # Code goes here
    for item in items:
        print(item)
    if item == "a":
        break
        print(item)

1 Answer

Steven Parker
Steven Parker
231,271 Points

Here's a few hints:

  • the entire item doesn't need to be "a", you should only match on the first letter
  • don't break the loop on a match, but continue to the next item
  • the "if" needs to be indented more to put it inside the loop
  • there should only be one print statement

thanks for the response.

I changed the lower part to this but still it doesn't pass. it just says try again.

       if item == [0]:
           continue
           print(item)
Steven Parker
Steven Parker
231,271 Points

Closer, but you need to apply the index to the item, and you still want to compare it with "a":

       if item[0] == "a":

Also, the "if" and "break" need to be indented more to put them inside the loop, and there should only be one "print" statement (after the "if").

Thank you so much for your help.

i did all of that and i also did indented the if in the loop but now it's says the right items aren't being printed and there is also only one print after the if

Steven Parker
Steven Parker
231,271 Points

Please show the whole code as it is now.

ok it's like this now

def loopy(items):
    # Code goes here
    for item in items:
        print(item)
        if item[0] == "a":
            continue
            print(item)

Thank you for your help but i figured it out

i could've just used this.

if item[0] != 'a':
Steven Parker
Steven Parker
231,271 Points

Actually, that would test for the wrong condition and not be correct. But it could work if you used it to control the "print" statement instead of the "continue".

The actual issues with that last version are:

  • there should only be one print statement (the last one)
  • that last print statement is indented too far