Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
215,956 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"