Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def e(n):
- # for type safety, and as we are exacting decimal cast the return value
- return float(1 + sum([1/math.factorial(a) for a in range(n) if a != 0]))
- x = 20
- # cut it off at 15 decimal places
- # append f to :.precision to round it up
- print("euler to 300 decimal places{:.20f}".format(e(x)))
- print("euler to 15 decimal places{:.15}".format(math.e))
- print("euler to 10 decimal places{:.10}".format(e(x)) , "{:.15}".format(math.e))
- # module above uses a convergering sequence to converge at euler number.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement