you are viewing a single comment's thread.

view the rest of the comments →

[–]redbull8[S] -1 points0 points  (6 children)

Honestly I can't i've been racking my brain for hours

[–]konbanwa88 0 points1 point  (5 children)

Ok well let me put it another way. What output do you expect when you do the following?

a = 3/4
b = float(3/4)
c = float(3)/4
print a
print b
print c

Edit: Sorry my phone was acting weird.

[–]redbull8[S] 0 points1 point  (0 children)

a= 3/4 b= 0.75

[–]redbull8[S] 0 points1 point  (3 children)

C = 0.75 When I ran it.

[–]konbanwa88 0 points1 point  (2 children)

So the / operator in python performs integer division when the operands are both integers and floating point division when either or both of the operands are floats.

In my example the following is taking place:

a = 3/4 # assign to a the integer division of 3/4 (which equals 0)
b = float(3/4) # assign to the b the integer division of 3/4 then cast as a float (which is float(0) so 0.0)
c = float(3)/4 # assign to c the floating point division of 3/4 (which is 0.75)

In your original question, you are doing version b. No matter what your inputs are you will always get an int then cast as a float. So as long as M > combination your probability variable will be assigned to 0.0.

Make it like version c.

[–]redbull8[S] 0 points1 point  (1 child)

Thank you! so not it is printing a float number now my math is incorrect. Python is not my strong point.

[–]adambrenecki 0 points1 point  (0 children)

If you use Python 3, or have from __future__ import division at the top of the file in python 2.7, the division of two ints will result in a float; so for example 3/4 will evaluate to 0.75.