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 trialBenjamin Peters
552 PointsHow do I finish this loop?
I wrote this in "Workspaces" first and it seems to work there, but it is not correct for the challenge task. What am I doing wrong?
items = []
def loopy(items):
print("What things are in items?")
print("Enter 'STOP' to finish adding things.")
while True:
thing = input("> ")
if thing == "STOP":
break
items.append(thing)
print("Here are your items:")
for thing in items:
print(items)
2 Answers
Kourosh Raeen
23,733 PointsHi Benjamin - For the challenges try to follow the instructions closely and avoid adding code that is not asked for. Here you only need a for loop, just like the one you have at the bottom of your code. Then inside the loop start with an if statement to see if the current item is "STOP". If it is break
, again very similar to the if statement you have in your code. Then after the if statement print the current item in the loop. Also, items
is passed into the function so don't define it in your code. Hope this Helps.
Benjamin Peters
552 PointsThanks! I'll give that a try.