Write a function that takes a number of rows, a number of columns, and a string and returns a two-dimensional array of the dimensions specified where each element is the string given. Sample run: mat = fill_str(4, 2, "2D​") print(mat) Prints the following: [['2D', '2D'], ['2D', '2D'], ['2D', '2D'], ['2D', '2D']]

Respuesta :

Answer:

Explanation:

The following code is written in Python. The function, as asked, takes in three parameters and creates a 2D array with the dimensions specified in the inputs and fills it with the element passed for the third parameter.

def createArray(rows, columns, element):

   my_array = []

   for x in range(rows):

       sub_arr = []

       for y in range(columns):

           sub_arr.append(element)

       my_array.append(sub_arr)

   return my_array

Ver imagen sandlee09