Skip to content

Instantly share code, notes, and snippets.

@peterldowns
Last active May 19, 2016 00:56
Show Gist options
  • Select an option

  • Save peterldowns/82bbc7efdf263d1c8b74e8163b3376b0 to your computer and use it in GitHub Desktop.

Select an option

Save peterldowns/82bbc7efdf263d1c8b74e8163b3376b0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
"""
The power of numbers is never more evident than when we use them to speculate
on the time of our dying. Sometimes I bargain with myself. Would I be willing
to accept sixty-five, Genghis Khan's age on dying? Suleiman the Magnificent
made it to seventy-six. That sounds all right, especially the way I feel now,
but how will it sound when I'm seventy-three?
Don DeLillo, White Noise
"""
from datetime import datetime as dt
adult_age = 18
death_age = 50
birth_dt = dt(year=1994, month=1, day=20)
adult_dt = birth_dt.replace(year=1994+adult_age)
death_dt = birth_dt.replace(year=1994+death_age)
now_dt = dt.utcnow()
birth = birth_dt.toordinal()
adult = adult_dt.toordinal()
now = now_dt.toordinal()
death = death_dt.toordinal()
days_lived = now - birth
days_adult = now - adult
days_remaining = death - now
lived_percentage = days_lived / float(death - birth) * 100
adult_percentage = days_adult / float(death - adult) * 100
def main():
print '{} days gone ({} as an adult), {} remaining ({:.2f}% alive, {:.2f}% adult)'.format(
days_lived, days_adult, days_remaining, lived_percentage, adult_percentage)
if __name__ == '__main__':
main()
@peterldowns
Copy link
Author

peterldowns commented May 12, 2016

$ python lifeclock.py
8155 days gone (1581 as an adult), 10107 remaining (44.66% alive, 13.53% adult)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment