human
What is a code to program for nth Catalan Number and the other steps required given the following:
Program for nth Catalan Number | A dynamic programming based function to find nth Catalan number.
Table to store results of subproblems.
Initialize first two values in table.
Fill entries in catalan [ ] using recursive formula.
Return last entry.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to program for nth Catalan Number and the other steps required.
 def catalan ( n ) :
	if ( n == 0 or n == 1 ) :
		return 1
	catalan = [ 0 ] * ( n + 1 )
	catalan [ 0 ] = 1
	catalan [ 1 ] = 1
	for i in range ( 2 , n + 1 ) :
		for j in range ( i ) :
			catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ]
	return catalan [ n ]
for i in range ( 10 ) :
	print ( catalan ( i ) , end = " ▁ " )