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

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Stuck

Stuck on this bit. -Do I need to create a 'string' with 'items' in it. -Is there a way to get examples without having to bother people? -How does everyone study i.e lets say for learning 'for loops'. As well as following Kenneths video's does everyone else take written notes or using Treehouse itself for reference i.e when you've forgotten how 'for loops ' work?

Thanks

Jamie

breaks.py
def loopy(items):
  items = "Hammer, nails"
    for word in 'items':
      print (word)
      if word == 'STOP':
        break

2 Answers

Codin - Codesmite
Codin - Codesmite
8,600 Points
def loopy(items):
  for word in items:
    if word == "STOP":
      break
    else:
      print(word)

You need to remove "" from around items in your for decleration, adding quotation marks around it causes it to become a string.

I do not do much Python programming as I am a PHP developer but normally I would refer to the PHP manual or for instance use google "PHP loop" if I was to forget the syntax.

Here is the python manual/documentation it has a search function to find what you are looking for:

https://docs.python.org/3/

Also there seems to be a pretty good wiki for Python with a search function here (The For Loop page for example): https://wiki.python.org/moin/ForLoop

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Thanks Ashley. That's great.

Steven Parker
Steven Parker
231,109 Points

Here's a few hints that might help you get a working solution:

  • the items will be passed to the function, you don't want to assign your own
  • items is a variable, you don't want to put quotes around it
  • the challenge wants you to stop before you print the word "STOP"