Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
i m getting Bummer: Try again on this task where am i going wrong?
Now create a variable named dt_2012 that uses filter() and is_2012 to return only the datetimes from dates that are from the year 2012.
import datetime dates = [ datetime.datetime(2012, 12, 15), datetime.datetime(1987, 8, 20), datetime.datetime(1965, 2, 28), datetime.datetime(2015, 4, 29), datetime.datetime(2012, 6, 30), ] def is_2012(argument): if argument.year == 2012: return True break dt_2012 = filter(is_2012, dates)
Steven Parker210,850 Points
You really close, but a "break" is only used with a loop, and there's no loop here. Plus the indentation doesn't line up.
Just remove that line entirely and you'll pass the challenge.
i did what you advised @Steven Parker but i still get the error
just tried it and it worked i don't know what was wrong at first
Thabang Richard Katlholo I looked at Steven Parker's advice (thanks by the way) and i fixed my code this way
import datetime dates = [ datetime.datetime(2012, 12, 15), datetime.datetime(1987, 8, 20), datetime.datetime(1965, 2, 28), datetime.datetime(2015, 4, 29), datetime.datetime(2012, 6, 30), ] # Part 1 def is_2012(argument): if argument.year == 2012: # The last mistake that made me lose patience and look for help, i typed # datetime.datetime.year instead of argument.year return True else: return False
And thanks to you Thabang Richard Katlholo, your code also helped mine.