[Tutor] Time Travel?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 4 Mar 2002 16:41:23 -0800 (PST)


On Mon, 4 Mar 2002, Kojo Idrissa wrote:

> Well, I'm glad Danny got a kick out of my "Version" scheme...
> 
> Here's the code:
> import time
> bday=(time.time()-(3600*24*213))
> age=bday/(3600*24*365.25)
> print "My current age is %2.6f" %age


Hmmm... let me check something:

###
>>> '%0.1f' % 0.66
'0.7'
>>> '%0.2f' % 0.66
'0.66'
###

The rounding behavior of format strings might account for the discrepency
in the space-time continuum.  As you've notice, int() doesn't round, but
instead truncates --- it just drops the fractional part of a float on the
ground:

###
>>> int(-4.5)
-4
>>> int(4.5)
4
###


You might want to use a round() in the expression:

> rev= int((minor-minor_ver)*10**6)


###
rev = int(round((minor-minor_ver)*10**6))
###

and thereby repair the singularity.


Good luck!