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

Challenge code Works on My Computer with python2 & python3

https://teamtreehouse.com/library/python-basics/shopping-list-app/break

def loopy(items): for item in items: if item == 'STOP': break print("* " + item) loopy(items)

[btihen@bt-laser:todo]$ python3 --version

Python 3.5.1

[btihen@bt-laser:todo]$ python --version

Python 2.7.11

[btihen@bt-laser:todo]$ python test.py

* tea

* bread

* dog food

[btihen@bt-laser:todo]$ python3 test.py

* tea

* bread

* dog food

MacOS - 10.11.3

breaks.py
def loopy(items):
  for item in items:
    if item == 'STOP': break
    print("* " + item)
loopy(items)
# [btihen@bt-laser:todo]$ python3 --version
# Python 3.5.1
# [btihen@bt-laser:todo]$ python --version
# Python 2.7.11
# [btihen@bt-laser:todo]$ python test.py 
# * tea
# * bread
# * dog food
# [btihen@bt-laser:todo]$ python3 test.py 
# * tea
# * bread
# * dog food
# MacOS - 10.11.3

2 Answers

Dan Garrison
Dan Garrison
22,457 Points

You should put your print in an else statement. Also, you only need your print to say print(item). You don't need the asterisk.

OK - I just figured if it breaks it terminates - otherwise the else happens without the else I removed the * & () too

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

I still get -- bummer - somrthing's wrong, but it works on my computer still