donsy
November 5th, 2011, 08:18 PM
Python 2.x correctly returns binomial coefficients and permutations as integers or longs. Why was this changed in py3?
Python 3.2.2 (default, Sep 5 2011, 22:09:30)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import factorial
>>> factorial(6)/(factorial(3)*factorial(3))
20.0
>>> factorial(6)
720
>>> factorial(6)/factorial(3)
120.0
>>>
I know I can always wrap the expressions in int(). But that shouldn't be necessary because binomial coefficients and permutations are always int's and it makes about as much sense as
>>> int(float(42))
42
>>>
Python 3.2.2 (default, Sep 5 2011, 22:09:30)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import factorial
>>> factorial(6)/(factorial(3)*factorial(3))
20.0
>>> factorial(6)
720
>>> factorial(6)/factorial(3)
120.0
>>>
I know I can always wrap the expressions in int(). But that shouldn't be necessary because binomial coefficients and permutations are always int's and it makes about as much sense as
>>> int(float(42))
42
>>>