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 trialWellington Souza
3,121 Pointsthe code tested in my computer does what is asked, skip the current item if it is starting with the character 'a'
""" 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". """
the input:
items
the output:
skip any item that has at the index 0 the character "a"
def loopy(items): for item in items: if item[0] == "a": continue print item
my_items = ["aquarium", "buy", "callable"] loopy(my_items)
"""
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".
"""
# the input:
# items
# the output:
# skip any item that has at the index 0 the character "a"
def loopy(items):
for item in items:
if item[0] == "a":
continue
print item
my_items = ["aquarium", "buy", "callable"]
loopy(my_items)
1 Answer
andren
28,558 PointsThe problem is your print line. In Python 3 (which is what Treehouse teaches) print
is a function, and as with all other functions you have to call it and provide it with values by using parentheses like this:
print(item)
Calling it and providing it values separated by a space is only valid in Python 2. Because of the fact that print
was actually considered a special statement in Python 2, not a function. If you simply correct the print function to look like the example I posted above then your code will be accepted.
Though it's also worth mentioning that the task technically only asks you to write the logic for the loopy
function, it does not ask you to actually call the function yourself. That doesn't create an issue in this specific challenge, but there are some challenges where your code will be marked as wrong if it does anything at all that was not specifically asked for. Including something as minor as calling the function yourself. So that's something you should keep in mind for future challenges.