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 trialAsad Malgi
641 PointsHELP ME Please in this Python task
HELP ME Please in this Python task. Please go through this code and please tell me where I am going wrong.
def loopy(items):
# Code goes here
red = ['car', 'tar','STOP', 'far']
items.append(red)
for a in red:
print(items)
if items == 'STOP':
break
Asad Malgi
641 Pointsi am trying this and this also doesn't work : def loopy(items): # Code goes here red = ['cat','mat','STOP','fat'] items.append(red) for a in red: if a == 'STOP': break else: print(a)
Jessica Sharp
4,018 Pointsyou don't need to make the red list , items is already there with STOP in it
Wade Williams
24,476 PointsThe function parameter "items" contains a list of items for you to loop through, so you don't need to create a list of items "red" or add your "red" to items. You're also printing the entire list of "items" within your loop then checking if the entire list of items is equal to 'STOP'.
You should re-structure your for loop to loop through "item in items", check if "item" is equal to 'STOP' and if not print item
def loopy(items):
# Code goes here
for item in items:
# if item is equal to 'STOP' break
# else print item
Asad Malgi
641 PointsThanks a lot for your help guys!!!
2 Answers
Steven Parker
231,271 PointsI see a few issues, here's some hints:
- don't add any static data to the passed-in argument list
- you can directly iterate over the argument list
- test and print the individual item, not the entire list
- be sure to test for
STOP
before you print it out
Wade Williams
24,476 PointsThe function parameter "items" contains a list of items for you to loop through, so you don't need to create a list of items "red" or add your "red" to items. You're also printing the entire list of "items" within your loop then checking if the entire list of items is equal to 'STOP'.
You should re-structure your for loop to loop through "item in items", check if "item" is equal to 'STOP' and if not print item
def loopy(items):
# Code goes here
for item in items:
# if item is equal to 'STOP' break
# else print item
Jessica Sharp
4,018 PointsJessica Sharp
4,018 Pointswell this is how i solved it
def loopy(items): for i in items: if i == "STOP": break else: print(i)
adding print to an else statement