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

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Second time around. Still got it wrong!

Am I Close?

breaks.py
def loopy(items):
    for word in items:
      if word == "STOP"
      break
      else:
        print(word)

1 Answer

akak
akak
29,445 Points

You are close but need to make a few changes. Remember that indentation and colons are important in Python.

def loopy(items):
    # Code goes here
  for word in items:
    if word == "STOP":
      break
    else:
      print(word)
jamie Macdiarmid
jamie Macdiarmid
2,048 Points

What is the best way to think of colons? Is it for every 'function'?

akak
akak
29,445 Points

Basically you put a colon before indenting to next line to indicate a code block start. And you do indent when you write a function so you can say it's for every function but also conditionals, loops and everywhere indentation is needed.