Python Python Basics (2015) Shopping List App Continue

Conner Williams
PRO
Conner Williams
Pro Student 3,065 Points

What does this mean?

I have no idea where to even start on this one.

breaks.py
def loopy(items):
    # Code goes here

4 Answers

Ben Reynolds
Ben Reynolds
35,166 Points

There's a few keywords in the instructions that give away some of the main points: Loop, If, otherwise (else).

A good way to break the ice when you're blanking is to map out the log with comments:

def loopy(items):
    # for each item in items
        # if something is true:
            # do one thing
        else:
            #do something else

You don't necessarily have to fill them in in order, pick away at the ones you can figure out and work your way down to the more tricky bits

Conner Williams
Conner Williams
Pro Student 3,065 Points

okay I'm getting closer. How do I tackle the "index" part?

Ben Reynolds
Ben Reynolds
35,166 Points

An index always starts at 0, and since strings are technically collections, each character has an index:

Here's a sample:

word = "Test"
first_letter = word[0]
Ben Reynolds
Ben Reynolds
35,166 Points

You could normally do it with the continue keyword, but I saw Steven's comment on the other thread you posted for this one and he's right, this can actually be done without continue or an else block. Here's my revised logic, the change in the "if" statement is the key:

def loopy(items):
    # for each item in items
        # if first letter is NOT a:
            # print something
Conner Williams
Conner Williams
Pro Student 3,065 Points

Here is what i have right now. It is giving me a "didnt find the right items printed" message. def loopy(items): # Code goes here for item in items: if item[0] is 'a': print(item)

Conner Williams
Conner Williams
Pro Student 3,065 Points

forgot to include "is not". I completed it. youre saving my life right now.

Ben Reynolds
Ben Reynolds
35,166 Points

Almost there

  1. The commented line "code goes here" can go
  2. There was a comment in my last post that is the last piece: # if first letter is NOT a:

There's a "not equal to" operator that need to replace the word "is" in your if statement