human
Can you provide a code to probability of getting K heads in N coin tosses and the other steps required given the following:
Probability of getting K heads in N coin tosses | Function to calculate factorial.
Applying the formula.
Driver code.
Call count_heads with n and r"
How can the above be solved in Python?
assistant
#Here is code to probability of getting K heads in N coin tosses and the other steps required.
 def fact ( n ) :
	res = 1
	for i in range ( 2 , n + 1 ) :
		res = res * i
	return res
def count_heads ( n , r ) :
	output = fact ( n ) / ( fact ( r ) * fact ( n - r ) )
	output = output / ( pow ( 2 , n ) )
	return output
n = 4
r = 3
print ( count_heads ( n , r ) )