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

Can't figure out this problem

It works perfectly fine when i try it in the workshop but when i try it here keeps saying its wrong?

breaks.py
def loopy(items):
    # Code goes here
    for stuff in items:
        if stuff == 'a':
            continue
        else:
            print(stuff)
            break

        print(stuff)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I wish I knew what data set you're testing in your workspaces. But you've got a couple of things going on here. First, you're supposed to be checking the 0 index of your stuff variable instead of the entire contents of stuff. Imagine that we have the list we're looking through and one of the items contains "apple". We want it to skip over that as it begins with the letter 'a'. However, your code will only skip things that are 'a' as opposed to things that simply start with them. Also, because you have the break in there, your code will exit the loop prematurely. Here's how I did it:

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

As you can see, this is very close to what you had. The biggest difference is that I removed the break and am now checking the first item in stuff. Hope this helps! :sparkles:

I see but i feel like this should still work. Checking 'a' doesnt check any letter of a word for example 'apple' the a doesnt matter. My orignal code was exactly the game except i didn't add the else i just told it to print(stuff):

def loopy(items):
    #Code goes here
    for stuff in items:
        if stuff == 'a':
            continue

        print(stuff)

the list i tried using was: items = ['a','apple','candy'] and i tried items = ['b','apple','candy'], in the first one it printed apple and candy while the second one printed b apple and candy so it worked.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Ralph Carrol I still think you might be misunderstanding the instructions. It wants you to take a list and from that list... print out anything that doesn't start with the letter a. So given your test data "apple" should not have printed out. If I were to use this: var items = ["anne", "mary", "bob", "alex", "tyra", "lisa", "aaron"] then after running the code it should print out "mary, bob, tyra, lisa" Everything beginning with the letter a should be skipped... not just the letter a. Hope this makes sense! :sparkles:

Ooooooh i see, i thought it was just the letter a!! ty so much ! :)