Question: Write a function called sequence_ab which takes 3 input parameters a, b and N and returns a Python list [x0, x1,...,xN] of length N

Write a function called sequence_ab which takes 3 input parameters a, b

Write a function called sequence_ab which takes 3 input parameters a, b and N and returns a Python list [x0, x1,...,xN] of length N + 1 representing the recursive sequence 1, x 1 1, Xn+2 = axn+1 + bxn For example, if a = b = 1 and N = 5 then the function returns the partial Fibonacci sequence [1,1,2,3,5,8]. [ ]: # YOUR CODE HERE = []: "Check function returns correct datatype. (1 mark)" assert type (sequence_ab (1,1,5)) == list "Return value should be a list." print("Problem 2 Test 1: Success!") [ ]: "Check function returns a list of the correct length. (1 mark)" assert len(sequence_ab(1,-1,23)) == 24, "Return value should be a list of length 24." print("Problem 2 Test 2: Success!") []: "Check function returns correct values. (1 mark)" assert sequence_ab(1,1,5) == [1,1,2,3,5,8], "Return value should be [1,1,2,3,5,8] when a=b=1 and N=5." print("Problem 2 Test 3: Success!") []: "Check function returns correct values. This cell contains hidden tests. (2 marks)" assert sequence_ab (1,-1,5): == [1,1,0,-1,-1,0], "Return value should be [1,1,0,-1,-1,0] when a=1, b=-1 and N=5.' print("Problem 2 Test 4: Success!") 11

Step by Step Solution

3.41 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!