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

Stefan Vaziri
Stefan Vaziri
17,453 Points

Loopy question - unsure if I need to define "items"

I think I got the "for...in" statements and "if...break" but it tells me that it didn't find the right items. Am I supposed to identify the item (items = xyz)?

breaks.py
def loopy(items):
  items = ["Apple", "Pears", "STOP"]
  for things in items:
    print(items)
    if items == "STOP":
      break

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You need to drop the assignment to items. An argument provided to the function (needed by the grader) will set this value.

Your check for "STOP" needs to be above the print to keep from printing "STOP".

Last, inside the loop, you need to reference the loop variable things instead of the parameter name items:

def loopy(items):
  for things in items:
    if things == "STOP":
      break
    print(things)
Stefan Vaziri
Stefan Vaziri
17,453 Points

So when you say drop the assignment, you mean that the order the code is written in has to go from "for...in" argument to "if" statement and then "print"?

Also, why do you reference the loop variable as "things" instead of the parameter name? Doesn't the "items" need a list of some sort? This is just a challenge question so it may not need that but for it to actually work, doesn't "items" need to be identified?

Taylor Quinn
Taylor Quinn
20,003 Points

Where does things come from? why isnt it items in loopy?