Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Continue

Hector Carrillo
Hector Carrillo
934 Points

need to understand where to put index at for the letter a being at index 0 also if the elif statement is even needed.

kinda getting lost completely dont know if im missing something or missing alot of information. to use index to skip 'a'

breaks.py
def loopy(items):
    for item in items
    if index[0] = 'a'
    break
    elif
    continue

4 Answers

Don't give up! You'r well on your way! :+1:

Your code is almost complete! However, there are a few minor problems. If you aren't able to solve this on your own with these hints, please reply! :smile:

  • Your are missing a lot of colons. For example, at the end of for item in items and if index[0] = 'a' there should be colons. If you don't know what a colon is, it's this character: :
  • You need indentation (basically meaning spacing before statements). Since Python doesn't use things like {} to represent blocks of code, you must indent to tell Python "This code is 'inside' this code, like a for loop, for example!". This is why spacing is very important in Python.
  • You shouldn't use elif. elif is used to chain conditions while else is used to do something if the if statement's condition isn't True. elif is similar to else, but it is run if the if isn't run, and the elif satisfies another condition! Think of elif as "else, if". It makes more sense that way :grin:
  • You can't use just one = to test if one value is equal to another. If you use that, Python will think you are assigning a variable called a[0] to the value 'a'. I'm not kidding. To tell Python to test if one value is equal to another, you must use the double equals operator. It look like this (with two equal signs): ==
  • You need to print the item if the first letter in the item isn't the letter 'a'. Read the instructions!
  • The variable index in index[0] isn't a variable you created, so Python doesn't know what to do with index. Did you mean to say item instead?

I hope these hints help. :smile:

~Alex

EDITED: Realized there was more errors in your code, updated my post

EDITED 2: Realized there was the index[0] thing which is also causing an error. Thanks Lucas Frischmann for noticing this!

Lucas Frischmann
Lucas Frischmann
1,397 Points

Hey guys,

I've few questions. Why is there index[0] and not items[0]? Why should we print items and not item?

Sorry it's maybe a newbie question :/

No, good catch! :grin:

I didn't see that. You found another error :+1:

Congrats on spotting that! :sparkles:

Apparently the code for the question (the code Hector Carrillo wrote) is very buggy :laughing:

Robert Bryan
Robert Bryan
2,869 Points

I am having similar issues with the same problem. Not sure how to translate the directions into code and getting "Bummer Try again!" does not give me any clues.

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

Thank you for the help...

You are extremely close. All that is wrong is the indentation.

:warning: You don't use {} to represent blocks (like in JavaScript you use {} to represent blocks) in Python, so indentation is important!

Add four more spaces to the beginning of each of the last three lines of code and you should watch your code pass :grin:

Also, use the variable item instead of index where you are doing index[0]. index isn't a variable you created so Python will throw an error because it doesn't know what index is!

~Alex

slavster
slavster
1,551 Points

Alexander Davison is mostly correct, you just need to make one tiny change to the last line of code.

The instructions indicate that it should print ONLY the items from the list which do NOT begin with "a". Your last line of code is saying, "print the entire list", which is not the same. You're almost there though!

Robert Bryan
Robert Bryan
2,869 Points

I think I have everything except for the print items that do not begin with "a".

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

Ok, your code is not working because you didn't indent this line enough:

print(items)

Python is very picky abut indentation, so you'll need to add an extra 4 spaces before it.

You either can indent, as I said above, or you can remove the if item[0] != 'a' completely. This is because if the first if condition if item[0] == 'a' is not True, then the else clause is run. So to make your code cleaner, you can just remove the line completely.