Python| sympy.catalan() 方法
借助sympy.catalan()方法,我们可以在 SymPy 中找到加泰罗尼亚数字。它表示为——
Syntax: catalan(n)
Parameter:
n – It denotes the nth Catalan number.
Returns: Returns the nth Catalan number.
示例 #1:
# import sympy
from sympy import * n = 4
print("Value of n = {}".format(n))
# Use sympy.catalan() method
nth_catalan = catalan(n)
print("Value of nth catalan number : {}".format(nth_catalan))
输出:
Value of n = 4
Value of nth catalan number : 14
示例 #2:
# import sympy
from sympy import * n = 15
print("Value of n = {}".format(n))
# Use sympy.catalan() method
nth_catalan = catalan(n)
print("Value of nth catalan number : {}".format(nth_catalan))
输出:
Value of n = 15
Value of nth catalan number : 9694845