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 Break

Challenge 2 of 2 Shopping List App Error

def loopy(items): # Code goes here current_item = input("> ") for item in items: if current_item == "STOP": break print(item)

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

You seemed to go a bit off track for the second part of the Challenge. You had it all going okay for the first one... Why did you change the name of variables and add a current_item variable. None of this was asked for in the second task. You do have all the 'elements' needed for the second task, but...

Your code from the first task:

def loopy(items):
    # Code goes here
    for item in items:    
        print(item)

Just needs 2 lines added inside of the for loop.

So, to fix your code up... first you need to delete the current_item = input("> "). This was not asked for by the challenge's instructions. The instructions are always very specific and need to be followed exactly, so I'm not sure why this was added?

Next, you need to change the variable names back to what you had for the first task. There was no need to change them, so I'm a bit confused as to why you did? You're looping over items and storing the value of each iteration in the temporary variable item. This is the only variable that you need to (and can) check against for the word "STOP" in the if statement.

Finally, you need to put the print method back inside of the for loop. Python is very indent dependent and by removing the indent, you moved it outside of the loop, so now the iterations through the loop are not being printed out any longer.

So, once all that is done, you end up with

def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
            break
        print(item)

I hope this helps. :)

Keep Coding! :dizzy: