Question: Write code using a while loop, that takes a non-empty list of integers from the user, as well as a width. Return a new list

Write code using a while loop, that takes a non-empty list of integers from the user, as well as a width. Return a new list where the original list has been converted into a two dimensional list with the specified width, padded with zeroes at the end as needed. You MAY NOT use any built-in functions/methods besides len() and .append(), you also may not use break statements. Also please use PYTHON 2.7.

Template:

#PROBLEM 1 def chop(l1,w): list1 = l1 width = w #YOUR CODE GOES HERE (indented) return list1 #END YOUR CODE 

Test Cases (must work with different test cases also):

chop [] 2 [[0, 0]] chop [1] 2 [[1, 0]] chop [1,2,3] 3 [[1, 2, 3]] chop [1,2,3,4,5,6,7] 3 [[1, 2, 3], [4, 5, 6], [7, 0, 0]] 

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!