I wish to find the approximate sum of exponential function , my code looks like this:
import numpy as np
import matplotlib.pyplot as plt
import math
N = input ("Please enter an integer at which term you want to turncate your summation")
x = input ("please enter a number for which you want to run the exponential summation e^{x}")
exp_sum =0.0
for n in range (0, N):
factorial = math.factorial(n)
power = x**n
nth_term = power/factorial
exp_sum = exp_sum + nth_term
print exp_sum
Now I tested it for a pair of (x, N) = (1,20) and it returns 2.0, I was wondering if my code is right in this context, if it is, then to get e = 2.71..., how many terms should I consider as N? if my code is wrong please help me fix this.