2 of 5
edited title
vnp
  • 54.7k
  • 4
  • 50
  • 137

Python: Computing \$e\$

I was trying to solve a problem which stated:

Calculate the first 10 digit prime found in consecutive digits of e.

I was able to solve the problem but I did it by using some 10k digits of e available online. So I tried to write a program which calculates digits of e. The problem is that it simply gives the incorrect answer.

The code and the formula I used are:

enter image description here

import math

e=0

x=int(input()) #larger this number, more will be the digits of e

for i in range(x):
    e+=(1/(math.factorial(i)))

print(e)

When the user inputs 10, the digits returned are 2.7182815255731922 which is not correct.

Can someone explain why is my code buddy?