168. Python Program to Calculate Age from a Date of Birth
Mediumdatetime
Overview
Mix strftime(), timedelta and an if to work out an age.
Problem Statement
Read a date of birth, then today's date, one per line, as YYYY-MM-DD. (Today's date is typed in, so the tests always give the same answer.) Print:
Born on aand the weekday name of the birth date.Age:and the age in whole years. Someone is a year older only once their birthday has come this year.Days lived:and the number of days from the birth date to today.
For example, for 2001-03-15 and 2025-03-14, one day before the 24th birthday:
Born on a Thursday
Age: 23
Days lived: 8765
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
Two dates, one per line. Example:
2001-03-15
2025-03-14
Output
The output for that example:
Born on a Thursday
Age: 23
Days lived: 8765
The tests try 4 different inputs.