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

Asad Malgi
Asad Malgi
641 Points

HELP ME Please in this Python task

HELP ME Please in this Python task. Please go through this code and please tell me where I am going wrong.

breaks.py
def loopy(items):
    # Code goes here
    red = ['car', 'tar','STOP', 'far']
    items.append(red)
    for a in red:
        print(items)
        if items == 'STOP':
            break

well this is how i solved it

def loopy(items): for i in items: if i == "STOP": break else: print(i)

adding print to an else statement

Asad Malgi
Asad Malgi
641 Points

i am trying this and this also doesn't work : def loopy(items): # Code goes here red = ['cat','mat','STOP','fat'] items.append(red) for a in red: if a == 'STOP': break else: print(a)

you don't need to make the red list , items is already there with STOP in it

Wade Williams
Wade Williams
24,476 Points

The function parameter "items" contains a list of items for you to loop through, so you don't need to create a list of items "red" or add your "red" to items. You're also printing the entire list of "items" within your loop then checking if the entire list of items is equal to 'STOP'.

You should re-structure your for loop to loop through "item in items", check if "item" is equal to 'STOP' and if not print item

def loopy(items):
    # Code goes here
    for item in items:
        # if item is equal to 'STOP' break
        # else print item
Asad Malgi
Asad Malgi
641 Points

Thanks a lot for your help guys!!!

2 Answers

Steven Parker
Steven Parker
231,236 Points

I see a few issues, here's some hints:

  • don't add any static data to the passed-in argument list
  • you can directly iterate over the argument list
  • test and print the individual item, not the entire list
  • be sure to test for STOP before you print it out
Wade Williams
Wade Williams
24,476 Points

The function parameter "items" contains a list of items for you to loop through, so you don't need to create a list of items "red" or add your "red" to items. You're also printing the entire list of "items" within your loop then checking if the entire list of items is equal to 'STOP'.

You should re-structure your for loop to loop through "item in items", check if "item" is equal to 'STOP' and if not print item

def loopy(items):
    # Code goes here
    for item in items:
        # if item is equal to 'STOP' break
        # else print item