Skip to content

Instantly share code, notes, and snippets.

@patricklucas
Created September 6, 2012 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patricklucas/3658115 to your computer and use it in GitHub Desktop.
Save patricklucas/3658115 to your computer and use it in GitHub Desktop.
Half-Life "Half Life" Calculator
"""Functions for calculating when the game Half-Life has been out for exactly
half of someone's life.
"""
import datetime
release_date = datetime.date(1998, 11, 19)
def for_birthdate(birth_date):
"""Given a person's date of birth, return the date on which Half-Life has
been out for half of their life.
"""
return release_date + (release_date - birth_date)
def birthdate_for_today():
"""Return someone's date of birth for which Half-Life has today been out
for half of their life.
"""
today = datetime.date.today()
return release_date - (today - release_date)
import datetime
import hlhl
def main():
print "If someone were born on %s, then today," % hlhl.birthdate_for_today()
print "Half-Life would have been out for exactly half of their life."
print
my_birthdate = datetime.date(1989, 3, 17)
my_hlhl = hlhl.for_birthdate(my_birthdate)
print "My birthdate:", my_birthdate
print "My Half-Life \"half life\":", my_hlhl
print "... missed it. :("
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment