Question: 2. Write a function adjust(vals, length) that takes as inputs a list vals and a non-negative integer length, and that returns a new list in

 2. Write a function adjust(vals, length) that takes as inputs a

2. Write a function adjust(vals, length) that takes as inputs a list vals and a non-negative integer length, and that returns a new list in which the value of vals has been adjusted as necessary to produce a list with the specified length. If vals is too short, the value that is returned should be padded with Os on the right-hand side: >>> adjust([1, 2, 3], 6) result: [1, 2, 3, 0, 0, 0] # pad with 3 Os to get a length of 6 >>> adjust([1, 2, 3], 4) result: [1, 2, 3, 0] # pad with one o to get a length of 4 If vals is either the correct length or too long, the list that is returned should consist of the first length elements of vals: >>> adjust([2, 4, 6, 8, 10], 4) result: [2, 4, 6, 8] # return the first 4 elements >>> adjust([2, 4, 6, 8, 10], 5) result: [2, 4, 6, 8, 10] # return first 5 elements all of it

Step by Step Solution

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 Databases Questions!