Python| sympy.genocchi() 方法
借助sympy.genocchi()方法,我们可以在 SymPy 中找到 Genocchi 数。
genocchi(n) -
Genocchi 数是一个整数序列G n满足关系 .
Syntax: genocchi(n)
Parameter:
n – It denotes the number upto which genocchi number is to be calculated.
Returns: Returns the nth genocchi number.
示例 #1:
# import sympy
from sympy import *
n = 7
print("Value of n = {}".format(n))
# Use sympy.genocchi() method
nth_genocchi = genocchi(n)
print("Value of nth genocchi number : {}".format(nth_genocchi))
输出:
Value of n = 7
Value of nth genocchi number : 0
示例 #2:
# import sympy
from sympy import *
n = 10
print("Value of n = {}".format(n))
# Use sympy.genocchi() method
n_genocchi = [genocchi(x) for x in range(1, 11)]
print("N genocchi number are : {}".format(n_genocchi))
输出:
Value of n = 10
N genocchi numbers are : [1, -1, 0, 1, 0, -3, 0, 17, 0, -155]