Welcome to the Treehouse Community
Looking to learn something new?
Create a function named is_over_13 that takes a datetime and returns whether or not the difference between that datetime
Lost in functions and date times.
import datetime birthdays = [ datetime.datetime(2012, 4, 29), datetime.datetime(2006, 8, 9), datetime.datetime(1978, 5, 16), datetime.datetime(1981, 8, 15), datetime.datetime(2001, 7, 4), datetime.datetime(1999, 12, 30) ] today = datetime.datetime.today() def is_over_13(dt): def date_string(dt): return dt.strftime("%B %d") birth_dates = map(date_string, filter(is_over_13, birthdays))
Ryan McGuire3,757 Points
So together without my messy comments def is_over_13(dt): difference=today-dt return difference.days>=4745
See below for thought process: Following the instructions and typing some code as I go.
Instruction: Create a function named is_over_13 that takes a datetime.
Now I know i need a function and its name and that it will take some "argument" so I type:
def is_over_13(dt): #I used dt but you could use x or y or asd.
Continuing to read: ....and returns whether or not the difference between that datetime and today is 4745 days or more (>=4745 days).
Let's add some more code. def is_over_13(dt): difference=today-dt #today is defined above, so we know we can use that. dt is the datetime coming in, so we can use that. difference we are just "making" or "declaring" now, you could also use the word delta or zxc if you want. return difference.days>=4745
from the question we see difference..... is 4745 days or more which means greater than or equal to AKA >=4745 days).
not sure where you got def date_string(dt):. Unless that is for next part of challenge it's not needed.