human
Program for nth Catalan Number | Returns value of Binomial Coefficient C ( n , k ).
since C ( n , k ) = C ( n , n - k ).
Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- -- * 1 ].
A Binomial coefficient based function to find nth catalan number in O ( n ) time.
Calculate value of 2 nCn.
return 2 nCn / ( n + 1 ).
Driver Code"
How can the above be solved in Python?
 Can you provide a code to program for nth Catalan Number and the other steps required?
assistant
#Here is code to program for nth Catalan Number and the other steps required.
 def binomialCoefficient ( n , k ) :
	res = 1
	if ( k > n - k ) :
		k = n - k
	for i in range ( k ) :
		res = res * ( n - i )
		res = res / ( i + 1 )
	return res
def catalan ( n ) :
	c = binomialCoefficient ( 2 * n , n )
	return c / ( n + 1 )
for i in range ( 10 ) :
	print ( catalan ( i ) , end = " ▁ " )