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

Ali S
Ali S
2,605 Points

I am having some trouble indenting for loops.

My task is: I need you to help me finish my loopy function. Inside of the function, I need a for loop that prints each thing in items.

Thank you

breaks.py
def loopy(items):
    for items in loopy:
        print items

2 Answers

Manish Giri
Manish Giri
16,266 Points

When you iterate through a list, you want to assign a temporary name to each item in the list, which you can then use in the loop. Example -

items = [1, 2, 3]
for i in items:
    # now i refers to each item in items, one by one

Now coming to your code, there are some problems -

def loopy(items):
    for items in loopy:
        print items
  1. loopy is the name of your function, not the name of your list, so for items in loopy is wrong.
  2. Your actual list is what's passed into your function - items. So you should iterate over items.
  3. Name your temporary variable something else, other than items, because items refers to the list itself. So, for example, you use the variable x - for x in items:

Now give it a shot!

Ali S
Ali S
2,605 Points

Thank you for the advice