-
-
Save douglasjarquin/1b767986182e3ebf302d8e399b92f4bb to your computer and use it in GitHub Desktop.
Inspired by Kevin Kelly's "My Life Countdown" - in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired by: http://kk.org/ct2/2007/09/my-life-countdown-1.php | |
# Life expectancy data: | |
# http://www.health.state.ny.us/health_care/medicaid/publications/docs/adm/06adm-5att8.pdf | |
$ python | |
>>> from datetime import date, timedelta | |
>>> birth_year = 1976 | |
>>> birth_date = date(1976,3,2) | |
>>> life_expectancy = 76.09 | |
>>> life_years = int(round(life_expectancy)) # 76 | |
>>> death_year = birth_year + life_years # 2052 | |
>>> birth_date_day_of_year = birth_date.timetuple()[7] # 62 | |
>>> percent_of_last_year = life_expectancy % 1 #.09 | |
>>> days_to_live_in_last_year = timedelta(days=birth_date_day_of_year+percent_of_last_year*365) | |
# Start from dec 31 to avoid off-by-one error | |
>>> the_day_i_will_die = date(death_year-1,12,31) + days_to_live_in_last_year | |
>>> the_day_i_will_die.ctime() | |
'Thu Apr 3 00:00:00 2052' | |
>>> days_lived = (date.today() - birth_date).days # 13149 | |
>>> days_until_i_die = (the_day_i_will_die - date.today()).days # 14642 | |
>>> total_days_i_will_live = (the_day_i_will_die - birth_date).days # 27791 | |
>>> mid_life_crisis = birth_date + timedelta(days=total_days_i_will_live/2) | |
>>> mid_life_crisis.ctime() | |
'Wed Mar 19 00:00:00 2014' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment