human
Probability of distributing M items among X bags such that first bag contains N items | Function to find factorial of a number.
Function to find nCr.
Function to find probability of first bag to contain N items such that M items are distributed among X bags.
Driver code.
Function call"
How can the above be solved in Python?
assistant
#Here is code to probability of distributing M items among X bags such that first bag contains N items and the other steps required.
 def factorial ( n ) :
	if ( n <= 1 ) :
		return 1 ;
	return n * factorial ( n - 1 ) ;
def nCr ( n , r ) :
	return ( factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ) ;
def Probability ( M , N , X ) :
	return float ( nCr ( M - N - 1 , X - 2 ) / ( nCr ( M - 1 , X - 1 ) * 1.0 ) ) ;
if __name__ == " _ _ main _ _ " :
	M = 9 ; X = 3 ; N = 4 ;
	print ( Probability ( M , N , X ) ) ;