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 trialIshan Rahman
2,155 PointsCan't seem to get the second challenge
What's wrong?
def loopy(items):
# Code goes here
for item in items:
if items == 'STOP':
break
print (items)
1 Answer
Alexander Davison
65,469 PointsYou are soooo close!
You are comparing the string "STOP"
to the list that is passed in. You are also print
ing the whole list.
The item
variable is a variable that will change through every iteration of the loop. For example, if I wrote this:
my_list = [1, 2, 3]
for x in my_list:
print(x)
It would print:
1
2
3
However, if I wrote:
my_list = ['a', 'b', 'c']
for x in my_list:
print(my_list)
It would print the whole list in each iteration:
['a', 'b', 'c']
['a', 'b', 'c']
['a', 'b', 'c']
Now that you've read these examples, let me point this out:
You are printing the entire list and comparing "STOP"
to the entire list.
You only need to compare and print the value of item
. Remember that this variable changes though each iteration.
Ishan Rahman
2,155 PointsIshan Rahman
2,155 PointsI got what you said. I did this but still it doesn't work.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsYou are still
print
ingitems
.