Advertisement
okpalan

Abstract Implementation of Euler number using a function

Nov 5th, 2021 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import math
  2. def e(n):
  3.     # for type safety, and as we are exacting decimal cast the return value
  4.     return float(1 + sum([1/math.factorial(a) for a in range(n) if a != 0]))
  5.  
  6. x = 20
  7. # cut it off at 15 decimal places
  8. # append f to :.precision to round it up
  9. print("euler to 300 decimal places{:.20f}".format(e(x)))
  10. print("euler to 15 decimal places{:.15}".format(math.e))
  11. print("euler to 10 decimal places{:.10}".format(e(x)) , "{:.15}".format(math.e))
  12. # module above uses a convergering sequence to converge at euler number.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement