[Tutor] round so only see 2 digits

alan.gauld@bt.com alan.gauld@bt.com
Mon, 4 Mar 2002 17:58:26 -0000


> What I'm trying to do is perform a computation on a number 
> (my age) to split it into three numbers, like a software 
> version number (Major.Minor.Revision).  

>>> def mkTriPart(a,b,c): return "%d.%d.%d" %(a,b,c)
>>> def splitTriPart(n): return map(int,n.split('.'))
>>>
>>> yrs = 42
>>> mnth = 11
>>> days = 7
>>> age = mkTriPart(yrs,mnth,days)
>>> print age
'42.11.7'
>>> y = splitTriPart(age)
>>> print "Yrs: %d  Mnths: %d  Days: %d" % (y[0],y[1],y[2])
Yrs: 42  Mnths: 11  Days: 7
>>> Maj = 2
>>> Min = 1
>>> Rev = 123
>>> vers = mkTriPart(Maj,Min,Rev)
>>> etc...

That kind of thing?

Alan g.