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 trialErik Luo
3,810 Points'function' object is not iterable
What's the problem?
def loopy(items):
for items in loopy:
if items == "STOP":
break
print (items)
2 Answers
Alexander Davison
65,469 PointsNice 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
3,810 PointsThank you
Name:GoogleSearch orJonathan Sum
5,039 Pointsthx for explain it. i don't know that too.
Alexander Davison
65,469 PointsNo problem :)
john larson
16,594 PointsThis 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
3,810 PointsI think the if has to be before print.
Name:GoogleSearch orJonathan Sum
5,039 Pointsjohn 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
john larson
16,594 Pointsjohn larson
16,594 Points