Division oddity

Jason Mobarak jmob at unm.edu
Mon Jan 12 04:49:45 EST 2004


Denis Sarrazin wrote:
> Try 1.0/2 instead of 1/2. Note that when I do eval("1/2") I get 0 not
> 0.5

Please note: "from __future__ import division", see PEP 238 which 
changes the behavior of the divisino operator.

My results with Python 2.3.3:

 >>> from __future__ import division
 >>> eval('1/2')
0.5
 >>> input()
1/2
0
 >>> eval(raw_input())
1/2
0.5

> 
> -Denis
> 
> Le Sun, 11 Jan 2004 23:45:48 +0000, Tim Rowe
> <tim at remove_if_not_spam.digitig.co.uk> a écrit :
> 
> 
>>If I do from __future__ import division then eval(1/2) gives me 0.5 as
>>expected. But if I do print input("enter a sum: ") and enter 1/2 as
>>the sum I get 0 as if I hadn't done the import.  I thought input was
>>supposed to give the same behaviour as an eval on raw input -- why the
>>difference here?
> 
> 




More information about the Python-list mailing list