#606 · Modules and random · Intermediate · 75 XP · about 15 min
Write birthday_info(born, today) where both are dates written 'YYYY-MM-DD', and born is never after today. Return a tuple (age, days_left): the person's age in whole years on today, and how many days are left until their next birthday, which is 0 when today is their birthday.
Someone born on February 29 has a real birthday only in leap years. In other years they celebrate on March 1, so on February 28 of such a year they are not a year older yet. calendar.isleap(year) tells you whether a year is a leap year.
birthday_info('2010-06-15', '2026-11-07') # returns (16, 220) birthday_info('2010-11-07', '2026-11-07') # returns (16, 0) birthday_info('2008-02-29', '2027-02-28') # returns (18, 1)
In the last example 2027 is not a leap year, so the birthday is on March 1, one day later.
First solves only, ranked by stars and then time.