import decimal import numpy as np from decimal import * getcontext().prec = 10000 def my_factorial (number): facto = Decimal ('1') for n in range (1, round (number) + 1, 1): facto = Decimal (facto) * Decimal (n) return facto bern = [] nmax = 2000 # n = 0 bern.append ((Decimal ('1'))) # n = 1 bern.append ((- Decimal ('1') / Decimal ('2'))) for n in range (2, nmax + 2, 1): temp = Decimal ('0') for i in range (0, round (n), 1): temp = Decimal (temp) - my_factorial (Decimal (n)) * Decimal (bern[i]) / (my_factorial (Decimal (n) + Decimal ('1') - Decimal (i)) * my_factorial (Decimal (i))) bern.append ((Decimal (temp))) for i in range (0, nmax + 2, 2): print ("") print ("", '{:5.0f}'.format (i), "") print ("", '{:102.100e}'.format (bern[i]), "") print ("") print ("")