use python as a calculator

Tim Wintle tim.wintle at teamrubber.com
Thu Jun 24 12:50:20 EDT 2010


On Thu, 2010-06-24 at 09:33 -0700, ilovesss2004 wrote:
> On Jun 24, 5:50 pm, Tim Harig <user... at ilthio.net> wrote:
> > On 2010-06-24, ilovesss2004 <yyiillu... at gmail.com> wrote:
> >
> > > If I run
> > > 1.0/10**10
> > > python will return 0
> >
> > Python 2.6.4 (r264:75706, Dec 11 2009, 23:02:59)
> > [GCC 3.4.6] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> > >>> 1.0/10**10
> > 1e-10
> >
> > What version are you using?
> >
> > > How can I make python return 1e-10?
> >
> > If necessary, cast everything to a float:
> >
> >
> >
> >
> >
> > >>> 1.0/float(10**10)
> > 1e-10
> 
> I use python 2.5
> Must change version? Is there any other solution?

Are you sure you're doing the above?

Testing on 2.5:

>>> 1.0/10**10
1e-10

... but if you leave off the ".0" it'll think you want integer
arithmatic, so return 0.

>>> 1/10**10
0

Tim




More information about the Python-list mailing list