joi, 14 mai 2015

Python Equillibrium

Some friends started talking about this:

and about the Millennial tipping point or equillibrium. And the discussion continued about doing this with Python. 
So I thought I'd give it a shot and exercise my Python muscle :)

Here's the code I came up with:

from sys import argv

script, byear, bmonth, bday = argv

from datetime import date
import time

today=date(int(time.strftime("%Y")),int(time.strftime("%m")),int(time.strftime("%d")))
new_mil=date(2001,1,1)
birthday=date(int(byear),int(bmonth),int(bday))
#Equilibrium time spent alive in the last millennium == time spent alive in this millennium
after=today-new_mil
before=new_mil-birthday

if after == before:
 print "Equilibrium"
elif after < before:
 print "You have " + str(before-after) +" days until Equillibrium"
 print "Equillibrium date: "+ str(today+(before-after))
else:
 print "You have " + str(after-before) + " days after Equillibrium"
 print "Equillibrium date: "+ str(today-(after-before))

Sample call & output:
PS D:\python_home> python .\milenium.py 1986 8 17
You have 5 days, 0:00:00 days until Equillibrium
Equillibrium date: 2015-05-19

PS D:\python_home> python .\milenium.py 1987 4 21
You have 242 days, 0:00:00 days after Equillibrium
Equillibrium date: 2014-09-14
I'm waiting for your comments and suggestions.

2 comentarii: