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 trialOtto linden
5,857 PointsWhat's wrong?
What's wrong whit my code?
def loopy(items):
for item in loopy:
print(item)
loopy(milk, water)
5 Answers
sradms0
Treehouse Project ReviewerYes correct. Do not copy and paste. Write it yourself, You will not learn otherwise.
The working code should produce the following:
def loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
items = ['a', 'b', 'STOP', 'c', 'd']
loopy(items)
a
b
STOP
Niko Klanecek
3,152 PointsFirst off for item in loopy:
is wrong. Your objective is to loop through items
, loopy
is just the name of the function. So the right way to do it is for item in items:
.
Second, your last line is not supposed to be there. It is also incorrect. If you wanted to do it that way you would have to do loopy(['milk', 'water'])
but don't do that because the instructions don't ask for that.
The way to solve the challenge is to stop printing when the item is 'STOP'
, so you need to add that logic like:
if item == 'STOP':
break
Otto linden
5,857 PointsYeah, I have it like this now but it dosent work still...??
def loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
sradms0
Treehouse Project Reviewerdef loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
def loopy(items):
for item in items:
print(item)
if item == 'STOP':
break
Your indentation of your condition check is off.
Otto linden
5,857 Pointsso what should I do? xD
sradms0
Treehouse Project ReviewerThe second block of code is a copy of yours, except it is slight different. Look very carefully at the differences between the first block and the second block.
Otto linden
5,857 PointsOnly that the if has no spaces before?
Otto linden
5,857 PointsI tried copy paste it but it didint work, it only says Bummer! Didn't find the right items being printed.
sradms0
Treehouse Project ReviewerYou're welcome.
Otto linden
5,857 Pointsbwt next time u help someone whit this, I think it easier to code it like this:
def loopy(items):
for item in items:
if item == 'STOP':
break
print(item)
sradms0
Treehouse Project ReviewerGood job. Putting print after condition will make sure 'STOP' is not printed :) You found it.
Otto linden
5,857 PointsOtto linden
5,857 Pointshmm, i have exactly like ur code but it dosent work?!
Otto linden
5,857 PointsOtto linden
5,857 Pointsor wait... typed loppy insted of loopy.. my bad! Thank you! :)