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

Erik Luo
Erik Luo
3,810 Points

'function' object is not iterable

What's the problem?

breaks.py
def loopy(items):
    for items in loopy:
        if items == "STOP":
            break
        print (items)
  • I believe you need to loop through items, not loopy
  • for item in items:
  • items probably represents a list that you will loop over
  • the whole parameter/argument thing takes some getting used to

2 Answers

Nice one, John! But, the reason it isn't passing the challenge is because you print the item first, so if the item was "STOP", it would print STOP then quit the loop. The challenge is expecting to break out of the loop immediately, and not print "STOP". Also, for Erik, the reason why your code isn't working is because you said "for items in loopy" (sorry, I do't understand why you did that :/), which won't pass the challenge, so instead you should say "for item in items" (and, when you do that, you should change the if statement's condition to item == "STOP"). This is the final result (which should work):

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

Hope this helps for both of you! :) ~Alex

Erik Luo
Erik Luo
3,810 Points

Thank you

No problem :)

This works in my editor, but it's not passing the challenge. I don.t know why.

def loopy(items):
    for item in items:
        print(item)
        if item == "STOP":
            break
Erik Luo
Erik Luo
3,810 Points

I think the if has to be before print.

Name:GoogleSearch orJonathan Sum
Name:GoogleSearch orJonathan Sum
5,039 Points

john larson

I saw some1 asked the same question before. Because you put the "If break"statement after printing out all of item of items, the "if break" statement can't check the keyword"STOP" in the items or not. (correct me if i am wrong~~i am still a noob...

items=["a","b","STOP","d"] # there are 4 item in items list.
for item in items:
        print(item)              #printing out item of items
       #a
       #b
       #STOP
       #d
if item =="STOP":   #after printing out all of item of items ,you put the "if break"statement is meaningless. How can the if statement checks which item is STOP after all of item has already printed?
    break