Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Break

Didier Borel
Didier Borel
2,837 Points

for loop print items

i don't quite see what I am doing wrong here

breaks.py
def loopy(items):
    for:input("> ")
    print(input)
    if: input=="STOP":
        break

3 Answers

Tatiana Perry
Tatiana Perry
17,156 Points
def loopy(items):
  for item in items:
    if item == "STOP":
      break
    print(item)

The if/break statement needs to be inside the loop before print.

Didier Borel
Didier Borel
2,837 Points

thxs Tatiana,

2 questions. what is the difference between == and = (1 or 2 equal signs)

and how do we know that item is a word python will understand, and differentiaite from items? is there a list of words or variables that python knows. ?

thxs

Steven Parker
Steven Parker
220,513 Points
  1. Two signs (==) is a test: "are these equal?". Just one = is an assigment: "copy the right side to the left side".
  2. You're talking about reserved words / language keywords. They are listed in the offical python docs.
Didier Borel
Didier Borel
2,837 Points

this Steven. that answers my question