Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions