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 trialAlbrino Fernando
1,577 PointsNeed Help Breaking
So I need help. My code as you can see below has part where its supposed to break. but I keep getting an error. I’ve tried similar problems on python shell and it works properly. why won’t this work???
def loopy(items):
for item in items:
print(item)
if items == "STOP":
break
Albrino Fernando
1,577 PointsHmmm.... Didn’t work, here’s my new code:
def loopy(items):
for item in items:
if item == "STOP":
break
print(items)
Antonio De Rose
20,885 PointsGood try, I do not see an issue with your code, if there is, I think, the indenting issue, could you please paste your code with a proper markdown, just like your first time.
1 Answer
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsSo you almost are there.
Kenneth doesn't want you to print the whole list of items, only each item. And then it asks you to conditionally check that item, if it equals "STOP" you want to break instead of print.
So
def loopy(items):
# items is a list of things
for item in items: # looping through each item
if item == "STOP": # conditionally check if a single item == "STOP"
break # if condition is True, we break
print(items) # if we reached this spot, we never break from loop. print the item.
I gave you lots of hints in those comments. See if you can find your error. You were close. Let me know if that helps.
Albrino Fernando
1,577 PointsI Tried Something New But I’m Still Getting An Error, New Code:
def loopy(items):
for item in items:
if item !== "STOP":
print(item)
else:
break
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsHey Albrino Fernando
So it looks like you are using an operator that you will see in other languages, but doesnt exist in Python
Python does not have the "strict" operator: !== you are trying to use as some other languages have.
Antonio De Rose
20,885 PointsAntonio De Rose
20,885 Points