I am attempting to create some code where the user is asked for their date of birth and today's date in order to determine their age. What I have written so far is:
print("Your date of birth (mm dd yyyy)")
Date_of_birth = input("--->")
print("Today's date: (mm dd yyyy)")
Todays_date = input("--->")
from datetime import date
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
age = calculate_age(Date_of_birth)
However it is not running like I would hope. Could someone explain to me what I am doing wrong?
date_of_birth
andtodays_date
instead. – Murrain"3 14 1995"
is just a string. Python won't interpret it as a date unless you tell it to. – Cantaloupe