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

nandini sn
nandini sn
901 Points

Problem am facing try again error

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

i need to loop all items in items until i get STOP , kindly help where am facing error

breaks.py
def loopy(items):
    for i in items:
        if items == 'STOP'
        break
        print(items)
    # Code goes here

2 Answers

Stuart Wright
Stuart Wright
41,119 Points

There are three issues with your code:

1) 'items' refers to the entire list. You need to amend your if statement and print statement to instead refer to a single element ('i' in this case).

2) You are missing the colon at the end of your if statement.

3) Your break statement is not correctly indented. It should be indented further to make clear that it is inside the if block.

nandini sn
nandini sn
901 Points

Thanks again :)

Douglas North
Douglas North
10,884 Points

you are saying if ITEMS when you should compare it to each iter so replace with i