All problems
Exponential Series Terms Needed
Problem
The Maclaurin series of exp(x) has terms |x|^k / k!. Return the smallest number of terms n (starting at k = 0) such that the first omitted term has magnitude below eps.
For x = 0 the answer is 1. Given x and eps, return n.
Hint
Update each term from the previous one by multiplying by |x| and dividing by the new index.
Test cases
case 1
in: [1,0.01]
expected: 5
case 2
in: [2,0.000001]
expected: 14
case 3
in: [0,2]
expected: 0
Starter codePython
def exponential_series_terms_needed(x, eps):
# Your code here
pass3 test cases · run your code against them in the editor