Age Calculator
Easy
5
2
56.5% Acceptance
In this lab, your task is to create a function named calculate_age
that calculates a person's age in years, months, and days. The function will take a single argument: the person's date of birth in the string format dd-mm-yyyy
.
Function Output
Your function should return a dictionary containing three keys: years
, months
, and days
. Each key should map to an integer representing the respective part of the age calculated.
Examples
- Example 1:
- Input: '01-01-2010'
- Expected Output:
{ 'years': 13, 'months': 0, 'days': 0 }
(assuming today's date is 01-01-2023)
- Example 2:
- Input: '15-06-2022'
- Expected Output:
{ 'years': 0, 'months': 6, 'days': 17 }
(assuming today's date is 01-01-2023)
Keep in mind to handle different scenarios like birthdays that have not occurred yet in the current year and edge cases like leap years. Good luck!
TIP: Make use of the datetime library to easily calculate the age