livepython.net

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:

  1. Born on a and the weekday name of the birth date.
  2. Age: and the age in whole years. Someone is a year older only once their birthday has come this year.
  3. 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.

Learn this firstChapter 18 · Python datetime Module: Dates, timedelta and strftime
solution.py
# write your code here

EXPECTED OUTPUT

1Born on a Thursday
2Age: 23
3Days lived: 8765

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.