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

The code works like asked on when in computer but the code challenge window says it is incorrect.

Same idea as the last one. My loopy function needs to skip an item this time, though. Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".

Above is the question asking to write code that will create output that skips over items in a list that start with the character 'a'.

Below is my code:

def loopy(items):
    for i in items:
        if i[0] == 'a':
            continue
        else:
            print i 

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Muaath! First, you're doing great! I'm not sure why this is working on your computer, to be perfectly honest. The print function requires a set of parentheses, and generally, has at least one argument, although this can be omitted if you're simply looking to print a new line.

The problem with your code is that the thing you are printing is not in parentheses. If I simply place the i inside a pair of parentheses after the print, your code passes!

Here's an example:

name = "Jennifer"
print(name)

You can find more documentation on input and output in Python here

Hope this helps! :sparkles:

Muaath likely has Python 2 installed on their computer. In python 2 print was not technically a function, but rather a special statement. It could somewhat be used like a function (with values passed in parenthesis) but it was actually designed to work with values that was just separated from it with a space. In the same way the return statement works.

That was changed in Python 3 to make it less confusing since so many people treated it like a function.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Thanks, andren! I don't think I ever did much (or anything) in Python 2. Handy information for future reference :thumbsup:

Thank you Jennifer the fix you mentioned worked. Andren is right I am learning both Python 2 and Python 3 at the same time. Which is why I didn't put the parenthesis around the i in print (i). When I ran the py file in the terminal/cmd window I got the output working using Python 2 not Python 3.