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

Python Python Basics (2015) Shopping List App Break

david kennedy
david kennedy
2,291 Points

I don't understand why this code doesn't pass

here is my code: def loopy(items): for item in items: if item != 'Stop': print item else: break

Also I tried to follow along with the shopping list code but I can't get it to run I get an exception error

breaks.py
def loopy(items):
    for item in items:
      if item != 'Stop':
        print item
      else:
        break

david kennedy - Could you please choose the answer that answered your question as a Best Answer? That would help others know what helped you and also give some extra points to the user that helped. If you need help on how to do that let me know :)

3 Answers

Your logic is sound and other than the fact that is it looking for "STOP" and not "Stop" I honestly see no reason for your code not to work.

I am not a fan of just giving the answer but this one is strange for me so i will straight up tell you that it is looking for the reverse. Maybe someone with a deeper understanding of Python can tell us why

def loopy(items):
    for item in items:
      if item == 'STOP':
        break
      else:
        print(item)

This is what it is looking for

doh! upon further investigation I stand corrected. You were 1. looking for 'Stop' instead of "STOP" AND you forgot your () around your print command. so....

def loopy(items):
    for item in items:
      if item != "STOP":
        print(item)
      else:
        break

works just fine once the typos are fixed :)

dang that was buggin me!

david kennedy
david kennedy
2,291 Points

Thanks Shawn! That makes sense! Now I can move on. Its also weird that I cant get the shopping list to work unless I use "raw_input" instead of "input" I guess thats a python 3 thing?

mocpanu paok
mocpanu paok
84 Points

Well, input() expects to read any time of variable i.e. integer number, float number, string. But in order to understand that it is a string it has to be presented with "". So for input() to work the user must provide a string "hello", but in raw_input() the user simply writes hello with no quotation marks. Hope I helped a little. :)

I found this raw_input vs. input hope it helps!