from datetime import date def calculate_age(born): today = date.today() return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
Here is what the above code is Doing:
1. It's defining a function called calculate_age.
2. It's taking a single parameter, born.
3. It's creating a variable called today, which is set to the current date.
4. It's returning the difference between today's year and the year the person was born, minus 1 if today's day and month are both less than the day and month of the person's birthday.