83.4k views
4 votes
Write a test program that prompts the user to enter a two dimensional array and displays the location of the smallest element in the array.

1 Answer

3 votes

Answer:

def element_loc():

is_end = 'n'

dimen2 = []

while is_end == 'n':

par1 = input("Enter rows and columns: ").split(",")

part = [int(i) for i in par1]

dimen2. append(part)

is_end = input("Do you want to add more rows? y/n: ")

mini = list()

for i in dimen2:

mini. append(min(i))

result = min(mini)

row_index = mini. index(result)

col_index = dimen2[row_index]. index(result)

print("Row: ", row_index, "Col_index: ", col_index)

element_loc()

Step-by-step explanation:

The python program solution above prompts users for the two-dimensional array and then the rows of the array are compared with the minimum value stored in another list or array. The row index and the column index are gotten from the mini and dimen2 arrays respectively and are displayed as the position of the minimum value in the two-dimensional array.

User Amarinediary
by
4.8k points