We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 31d5aeb commit 9c708ecCopy full SHA for 9c708ec
n_digit_e.py
@@ -0,0 +1,28 @@
1
+# find e to nth digit by brothers' formulae: http://www.intmath.com/exponential-logarithmic-functions/calculating-e.php
2
+import decimal
3
+
4
5
+def factorial(n):
6
+ factorials = [1]
7
+ for i in range(1, n + 1):
8
+ factorials.append(factorials[i - 1] * i)
9
+ return factorials
10
11
12
+def compute_e(n):
13
+ decimal.getcontext().prec = n + 1
14
+ e = 2
15
+ factorials = factorial(2 * n + 1)
16
17
+ counter = 2 * i + 2
18
+ denominator = factorials[2 * i + 1]
19
+ e += decimal.Decimal(counter / denominator)
20
+ return e
21
22
23
+while True:
24
+ n = int(input("Please type number between 0-1000"))
25
+ if n >= 0 and n <= 1000:
26
+ break
27
28
+print(str(compute_e(n))[:n + 1])
0 commit comments