Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > use python as a calculator

Reply
Thread Tools

use python as a calculator

 
 
ilovesss2004
Guest
Posts: n/a
 
      06-24-2010
If I run
1.0/10**10
python will return 0

How can I make python return 1e-10?
 
Reply With Quote
 
 
 
 
Thomas Jollans
Guest
Posts: n/a
 
      06-24-2010
On 06/24/2010 05:42 PM, ilovesss2004 wrote:
> If I run
> 1.0/10**10
> python will return 0
>
> How can I make python return 1e-10?


It returns 1e-10.
 
Reply With Quote
 
 
 
 
Tim Harig
Guest
Posts: n/a
 
      06-24-2010
On 2010-06-24, ilovesss2004 <> 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
>>>

 
Reply With Quote
 
D'Arcy J.M. Cain
Guest
Posts: n/a
 
      06-24-2010
On Thu, 24 Jun 2010 08:42:32 -0700 (PDT)
ilovesss2004 <> wrote:
> If I run
> 1.0/10**10
> python will return 0
>
> How can I make python return 1e-10?


What version of Python are you using?

Python 2.6.4 (r264:75706, Jan 28 2010, 11:26:00)
[GCC 4.2.1 20070719 [FreeBSD]] on freebsd7
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.0/10**10

1e-10

--
D'Arcy J.M. Cain <> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
 
Reply With Quote
 
ilovesss2004
Guest
Posts: n/a
 
      06-24-2010
On Jun 24, 5:50*pm, Tim Harig <user...@ilthio.net> wrote:
> On 2010-06-24, ilovesss2004 <yyiillu...@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?
 
Reply With Quote
 
Tim Wintle
Guest
Posts: n/a
 
      06-24-2010
On Thu, 2010-06-24 at 09:33 -0700, ilovesss2004 wrote:
> On Jun 24, 5:50 pm, Tim Harig <user...@ilthio.net> wrote:
> > On 2010-06-24, ilovesss2004 <yyiillu...@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

 
Reply With Quote
 
Etienne Rousee
Guest
Posts: n/a
 
      06-24-2010
Le 24/06/2010 18:33, ilovesss2004 a écrit :

> I use python 2.5
> Must change version? Is there any other solution?


With python 2.6.5, I obtain 1e-10.

--

Etienne

 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      06-24-2010
ilovesss2004 wrote:

> If I run
> 1.0/10**10
> python will return 0
>
> How can I make python return 1e-10?


If you meant 1/10**10, by default this returns an integer in Python 2.x.
With "from __future__ import division" you can opt for the division of
integers to return a float:

>>> 1/10**10

0
>>> from __future__ import division
>>> 1/10**10

1e-10

Python 3.x will return a float by default.

Peter

 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      06-24-2010
On Thu, Jun 24, 2010 at 10:33 AM, ilovesss2004 <> wrote:
> I use python 2.5
> Must change version? Is there any other solution?


It works for me:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.0/10**10

1e-010

Perhaps you're doing integer division by mistake?

>>> 1/10**10

0L

Cheers,
Ian
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MCSE exam can you use a calculator? =?Utf-8?B?UmVk?= MCSE 9 06-29-2007 05:34 PM
[ANN] rpncalc-1.1 RPN Calculator For Python Raymond L. Buvel Python 0 12-21-2004 09:27 PM
[ANN] rpncalc-1.0 RPN Calculator For Python Ray Buvel Python 6 11-28-2004 07:43 PM
ANN: rpncalc-1.0 RPN Calculator For Python Raymond L. Buvel Python 0 11-28-2004 12:48 PM
ANN: pcalc 3.0 - a Python powered MFC calculator Gerson Kurz Python 0 12-04-2003 06:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57