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

Please explain why: def loopy(items): for i in items: print i is not correct

Please explain why: def loopy(items): for i in items: print i is not correct

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

3 Answers

andren
andren
28,558 Points

The loop itself is fine, the issue is the print line.

In python 3 which is what is thought and used at Treehouse print is a function, which means that you have to call it and pass values by using parenthesis like this:

print("Thing you want to print")

You can't just type print and then the value seperated by a space, that is valid syntax only in Python 2 due to the fact that print was considered a statement rather than a function in that version of Python.

So to summarize, your code is valid in Python 2, but not Python 3. If you add the parenthesis needed to your code like this:

def loopy(items):
    for i in items:
        print(i)

Then you'll pass the first task.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Juan,

print is a python method and therefore requires () with the argument passed inside. So, instead of

print i

You need to have

print(i)

Keep Coding! :dizzy:

Great Many thanks!!