Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started