Examples :
Input: 1996-11-12
Output: [ ’1996-11-12’, ’2002-11-12’, ’2013-11-12’, ’2019-11-12’, ’2024-11-12’, ’2030-11-12’, ’2041 -11-12 ’,’ 2047-11-12 ’]Input: 1992-11-2
Output: [’ 1992-11-2 ’,’ 1998-11-2 ’,’ 2009-11-2 ’,’ 2015-11-2 ’,’ 2020-11-2 ’,’ 2026-11-2 ’,’ 2037- 11-2 ’,’ 2043-11-2 ’,’ 2048-11-2 ’]
Recommended: please , try your approach on first before moving on to the solution.
Functions generated:
- split_date (birthdate): this function splits the user-supplied date into year, month and day.
- get_birthday (birthdate): this the function is used to return the day of the week the user was born.
- true_birthdays (date of birth): this function is used to return a list of dates that have the same day of the week the user was born.
There are three methods to find birth dates that have the same day the user was born above. First, the user split_date ()
is the date, and split_date ()
will split the date into year, month and day. The get_birthday ()
function will then be used to find the day of the week for that particular date. Finally, true_birthdays ()
will be used to find a list of all dates that have the same day of the week. Inside this function, the for loop will iterate from year of birth to a specific year and will check if the date of birth is in any specific year with the same day of the week or not. If the day of the week is the same, then that date will be added to the list of dates.
Below is the implementation.
|
Exit:
[’1996-11-12’, ’2002-11-12’, ’2013-11-12 ’,’ 2019-11-12 ’,’ 2024-11-12 ’,’ 2030-11-12 ’,’ 2041-11-12 ’,’ 2047-11-12 ’]