Compute Age

Let’s consider a str s with a text with 2 parts ended by a dot (the character ‘.’). For instance 'Today is 1/10/2024. My birthday is the 15/7/1964.'. Each part includes a date right before the dot. The date of the 1st part is today’s date and the date in the 2nd part is person’s birthday. As you can see in the example, dates are expressed in the format day/month/year where day has one or two digits, month has one or two digits and year has 4 digits.

We wish to get a text indicating the age of that person. The format required is 'You are X years old.' where X is the current age of our person, except if today is that person’s birthday in which case the format must be 'Happy Xth birthday !' where X is that person’s current anniversary.

You are required to deliver the two functions (they have the same grade weight) in the module age_module (file age_module.py). .

Firstly, an auxiliar function specified as follows:

extract_date(s)

such that

given s a str with a date in the format described above

returns 3 int corresponding to the day, month and year of that date in this order.

For example:


>>> extract_date('Today is 1/1/2024')
(1, 1, 2024)

>>> extract_date('Today is 1/10/2024')
(1, 10, 2024)

>>> extract_date('My birthday is the 15/7/2024')
(15, 7, 2024)

>>> extract_date('I celebrate my birthday on 15/12/2024')
(15, 12, 2024)

Doctests are available in the extract_date.test file.


Secondly, the main function (using the previous function is advised):

age_comp(s)

such that

given s a str with the format described above.

returns a str generated as described above.

For example:


>>> s = 'Today is 1/10/2024. My birthday is the 15/7/1964.'
>>> age_comp(s)
'You are 60 years old.'

>>> s = 'The date today is 1/10/2024. I celebrate my birthday on 15/12/1964.'
>>> age_comp(s)
'You are 59 years old.'

>>> s = 'Today is 1/10/2024. The day I celebrate my birthday with my friends and family is the 1/10/2004.'
>>> age_comp(s)
'Happy 20th birthday !'

>>> s = 'Today is 1/1/2024. My birthday is 2/2/2004.'
>>> age_comp(s)
'You are 19 years old.'

Doctests are available in the age_comp.test file.