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 trial
William Brown
1,303 Pointsbreak.py is not working there is a bug
def loopy(items): cool = [] var1 = cool.append(items) for thing in cool: print(thing) if thing == "STOP": break
jacinator
11,936 PointsI'm guessing that this is what you're code looks like.
def loopy(items):
cool = []
var1 = cool.append(items)
for thing in cool:
print(thing)
if thing == "STOP":
break
Nate Sturgeon
2,255 PointsAlthough this wont fix your problem completing the challenge, it will help your code be more clean and straightforward:
You can get rid of your first two lines of code within the loopy function! Instead, just take the variable items which gets passed into the function, and feed it into your for loop. In practice, it looks like this:
def loopy(items):
for thing in items:
...
1 Answer
Nate Sturgeon
2,255 PointsOne possibility that jumps out at me right away is the order of operations in your for loop. The way you've written it, it prints out each item in the iterable thing BEFORE checking if each item is "STOP" and thus breaking the loop. This doesn't follow the instructions exactly (even though it is very close) because in your case, you will be printing out "STOP" which is not necessarily desirable.
Try adjusting the order within your for loop so that the if ... break loop runs before your print statement, and see if that works.
Other than that, it is hard to tell if there are other potential issues because the code in your post above shows no newlines or spacing, all of which are important for python code to run properly.
Ryan S
27,276 PointsRyan S
27,276 PointsHi William,
Could you link to the challenge you are working on? Also, see the Markdown Cheatsheet on how to format your code in the forum. It's easier to troubleshoot when we can see it properly formatted.
Thanks!