Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 386: 11.13

Answer

code

Work Step by Step

# 11.13 (Locate the largest element) Write the following function that returns the location # of the largest element in a two-dimensional list: # def locateLargest(a): # The return value is a one-dimensional list that contains two elements. These # two elements indicate the row and column indexes of the largest element in the # two-dimensional list. Write a test program that prompts the user to enter a two dimensional # list and displays the location of the largest element in the list. def locateLargest(a): max_indx_row = 0 max_indx_col = 0 for i in range(len(a)): for j in range(len(a[i])): if a[i][j] > a[max_indx_row][max_indx_col]: max_indx_row = i max_indx_col = j return max_indx_row, max_indx_col rows = int(input("Enter the number of rows in the list: ")) matrix = [] for i in range(rows): r = input("Enter a row: ").split() r = [float(x) for x in r] matrix.append(r) row, col = locateLargest(matrix) print("The location of the largest element is at (" + str(row) + "," + str(col) + ")")
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.