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
Muaath Alaraj
879 PointsThe 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
Treehouse TeacherHi 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!
andren
28,558 Pointsandren
28,558 PointsMuaath likely has Python 2 installed on their computer. In python 2
printwas 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 thereturnstatement works.That was changed in Python 3 to make it less confusing since so many people treated it like a function.
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherThanks, andren! I don't think I ever did much (or anything) in Python 2. Handy information for future reference
Muaath Alaraj
879 PointsMuaath Alaraj
879 PointsThank 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.