Question

This needs to be in python, however, I am having trouble with the code. Is there...

This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it?

#Create main method
def main():
#Create empty list
list=[]
#Display to screen
print("Please enter a 3 x 4 array:")
#Create loop for rows and have each entered number added to list
for i in range(3):
list.append([int(x) for x in input().split()])
#Display the entered array
print("The entered matrix:")
for i in range(3):
for x in range(4):
if(x==3):
print(list[i][x],end="\n")
else:
print(list[i][x],end=" ")
  
#Create locateLargest method
def locateLargest(list):

#Call the main method
if __name__=="__main__":
main()

Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location of the first largest value in a two-dimensional array. The largest values may appear more than once in the array. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out the matrix, and then calls method locateLargest(). Finally, it prints out the array retuned by method locateLargest(). Document your code, and organize and space the outputs properly as shown below.

Sample run 1:

The entered matrix:

9   1   2    4

2    11   18   20

3   20   3   12

First largest value is located at row 1 and column 3

Sample run 2:

The entered matrix:

19   11 22   44

29 51   81   20

23   90   45 90

First largest value is located at row 2 and column 1

Sample run 3:

The entered matrix:

89   11 22 44

29   51 80   20

33   10 45   10

First largest value is located at row 0 and column 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def main():
#Create empty list
list=[]
#Display to screen
print("Please enter a 3 x 4 array:")
#Create loop for rows and have each entered number added to list
for i in range(3):
list.append([int(x) for x in input().split()])
#Display the entered array
print("The entered matrix:")
for i in range(3):
for x in range(4):
if(x==3):
print(list[i][x],end="\n")
else:
print(list[i][x],end=" ")
return list#returning created list
#Create locateLargest method
#method to find and display the largest element in the matrix
def locateLargest(list):
n = len(list)
m = len(list[0])
maxi=[0,0]#colum and row indexes of largest element
for i in range(n):
for j in range(m):
if(list[maxi[0]][maxi[1]]<list[i][j]):
maxi=[i,j]#updating indexes for largest element
#displaying result
print("First largest value is located at row ",maxi[0]," and column ",maxi[1])
l=main()
locateLargest(l)

output:

please enter a 3 x 4 array:   
9 1 2 4   
2 11 18 20
3 20 3 12   
The entered matrix:   
9 1 2 4   
2 11 18 20
3 20 3 12   
First largest value is located at row 1 and column 3


//PLS give a thumbs up if you find this helpful, it helps me alot, thanks.


//if you have any doubts, ask me in the comments

//use indentation given in the image below

Add a comment
Know the answer?
Add Answer to:
This needs to be in python, however, I am having trouble with the code. Is there...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SOLVE IN PYTHON: Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location...

    SOLVE IN PYTHON: Exercise #2: Develop a program (name it LocateLargestElement) that prints out the location of the first largest value in a two-dimensional array. The largest values may appear more than once in the array. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints out...

  • IN C#.Develop a program that prints out the location of the largest value in a two-dimensional...

    IN C#.Develop a program that prints out the location of the largest value in a two-dimensional array. The largest values may appear more than once in the array, so you must only print out the first instance. The program defines method locateLargest() that takes a two-dimensional array of integers and returns the location (row index and column index) of the first largest value as a single-dimensional array. The program main method prompts the user to enter a 3-by-4 matrix, prints...

  • I need this code in C++. Should be able to read from a file as stated...

    I need this code in C++. Should be able to read from a file as stated in the directions Exercise #1: Develop a program that prints out the sum of each column of a two-dimensional array The program defines method sumColumn takes a two-dimensional array of integers and returns a single dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and...

  • I need assistance writing the following Java class. Design a class named Location for locating a...

    I need assistance writing the following Java class. Design a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: public static Location locateLargest(double[][]...

  • This is for Java. Create ONE method/function that will return an array containing the row and...

    This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...

  • this language is JAVA 2. Design a class named Location for locating a maximum value and...

    this language is JAVA 2. Design a class named Location for locating a maximum value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: Public static Location locateLargest(double [][] a) Create...

  • Code in Java and implement (source code) a program (name it WeeklyHours) to compute the total...

    Code in Java and implement (source code) a program (name it WeeklyHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers’ daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers between 0 and 10 and...

  • C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a...

    C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional...

  • I am writing python code. I submitted an assignment but the professor said it was a...

    I am writing python code. I submitted an assignment but the professor said it was a modularization. Can you help me see what part of the code is modularization? Pseudocode: 1. Decalre MainMethod () function: # A. Parameters: Three numbers # B. Put the three numbers in reverse # 2. Main Program # A. Initialize Varibles # B. Accepts three values from the user # C. Invoke MainMethod () function, passing the three numbers as arguments in reverse # D....

  • Program 5: Design (pseudocode) and implement (source code) a program (name it Weekl yHours) to compute...

    Program 5: Design (pseudocode) and implement (source code) a program (name it Weekl yHours) to compute the total weekly hours for 3 employees. The program main method defines a two-dimensional array of size 3x7 to store employers' daily hours for the week. Each row represents one employee and each column represent one day of the week such that column 0 designates Monday, column 1 designates Tuesday, etc. The program main method populates the array with random numbers between 0 and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT