Created
September 6, 2012 16:23
-
-
Save patricklucas/3658115 to your computer and use it in GitHub Desktop.
Half-Life "Half Life" Calculator
This file contains 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
"""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) |
This file contains 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
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." | |
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