Problem 2 (3 points) Write a function called log taylor which takes one input pa
ID: 3751365 • Letter: P
Question
Problem 2 (3 points) Write a function called log taylor which takes one input parameter N and returns a Python list of length N representing the sequence {ai , a2, . .. , aN } of coefficients of the Taylor polynomial Tv(x) of degree N of ln(1 +x) k-1 In other words, the function returns the list [ai,a2.... ,av] where ak Hin [ ]: # YOUR SOLUTION GOES HERE In "Check that log_taylor returns the correct datatype." assert type (log taylor(3))list,"Return value should be a list." assert len(log taylor (3)3"Return value should be a list of length 3 when N-3. print("Problem 2 Test 1: Success!") In "Check that log_taylor returns the correct values." assert log taylor(1)[1.0Value log_ taylor (1) should be 1.01." print("Problem 2 Test 2: Success!")Explanation / Answer
def log_taylor(n): lst = [] for k in range(1, n+1): lst.append(((-1)**(k+1)) / k) return lst
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.