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

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

I would like to know what I am doing wrong in this code

def loopy(items): for thing in items: elif: item = "Stop" break else:

breaks.py
def loopy(items):
    for thing in items:
        elif:
            item = "Stop"
            break
        else:
            print(thing)

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi George, there's a few small issues with your code.

1. You can't have an elif condition check without first starting with an if conditional check. In this case a single if/else statement is enough, no need to use an elif.

2. A single equals is an assignment operation. Make sure to use a double equals when performing a comparison.

3 The variable you are using to refer to each item in the for loop is thing, however inside the for loop you are referring to a variable item in the conditional check (which in this case should be thing). I'd recommend renaming the thing variable to item, as it makes more sense.

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