[Tutor] value of 'e'
Kent Johnson
kent37 at tds.net
Tue Nov 24 13:33:11 CET 2009
On Tue, Nov 24, 2009 at 7:19 AM, Lie Ryan <lie.1296 at gmail.com> wrote:
> Shashwat Anand wrote:
>>
>> How can it be done ?
>
>>>> import decimal, math
>>>> D = decimal.Decimal
>>>> decimal.getcontext().prec = 100
>>>> sum(D(1) / D(math.factorial(i)) for i in range(1000))
> Decimal('2.718281828459045235360287471352662497757247093699959574966967627724076
> 630353547594571382178525166428')
And with the correct arithmetic, as above, there is no need to compute
so many terms.
You just have to get to a value of i for which i! > 10^100. i=80 works:
In [8]: sum(D(1) / D(math.factorial(i)) for i in range(80))
Decimal('2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166428')
Kent
More information about the Tutor
mailing list