Last active
September 23, 2018 15:09
-
-
Save md2perpe/6a3819798b2da731449dd945deeecb2c to your computer and use it in GitHub Desktop.
Calculate Eulers number (e)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.facebook.com/groups/progfml/permalink/344454616128233/ | |
from math import factorial | |
e=0 | |
n=0 | |
step_length=1 | |
e_right=2.71828 | |
margin_of_error=0.001 | |
Klart=False | |
while Klart != True: | |
for k in range (0,n+1): | |
a=factorial(k) | |
e=e+1/a | |
print("a=%d, 1/a=%f, e=%f" % (a, 1/a, e)) | |
difference= e_right - e | |
if difference <= margin_of_error: | |
Klart=True | |
if difference > margin_of_error: | |
n=n+1 | |
print (n,e,difference) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment