1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ira Lisetskai [31]
3 years ago
8

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.
Computers and Technology
1 answer:
alexandr1967 [171]3 years ago
8 0

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()

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.

You might be interested in
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balance
Simora [160]

Answer:

// Scanner class is imported to allow program receive user input

import java.util.Scanner;

// class is defined

public class PlayerRoster {

   // main method that begin program execution

  public static void main(String[] args) {

   // Scanner object scan is defined

     Scanner scan = new Scanner(System.in);

   // multi-dimensional array to hold the jersey number and rating

     int[][] players = new int[5][2];

   // boolean flag to keep program alive

     boolean keepAlive = true;

   // the user input is declared as input of type char

     char input;

     

   // for loop that receive 5 player jersey number and ratings

   // it assigns the received input to the already initialized array

     for (int i = 0; i < 5; i++) {

        System.out.println("Enter player " + (i+1) + "'s jersey number: ");

        players[i][0] = scan.nextInt();

        System.out.println("Enter player " + (i+1) + "'s rating: ");

        players[i][1] = scan.nextInt();

        System.out.println();

     }

   // a blank line is printed

     System.out.println();

   // a method is called to display players array

     outputRoster(players, 0);

     

   // while the flag is true

   // display the Menu by calling the outputMenu method

     while (keepAlive) {

        outputMenu();

       // user input is assigned to input

        input = scan.next().charAt(0);

       //  if user input is 'q' then program will quit

        if (input == 'q') {

           keepAlive = false;

           break;

        }

       //  else if input is o, then outputRoaster is called to display players

        else if (input == 'o') {

           outputRoster(players, 0);

        }

       //  else if input is 'u', then user is allowed to edit a player rating

        else if (input == 'u') {

           System.out.println("Enter a jersey number: ");

           int jerseyNum = scan.nextInt();

           System.out.println("Enter a new rating for the player: ");

           int newRating = scan.nextInt();

           for (int l = 0; l < 5; l++) {

              if (players[l][0] == jerseyNum) {

                 players[l][1] = newRating;

              }

           }

        }

       //  else if input is 'a', user is allowed to add a new rating

        else if (input == 'a') {

           System.out.println("Enter a rating: ");

           int rating = scan.nextInt();

           outputRoster(players, rating);

        }

        // else if input is 'r', user is allowed to replace a player

        else if (input == 'r') {

           System.out.println("Enter a jersey number: ");

           int jerseyNum = scan.nextInt();

           boolean exists = true;

           for (int l = 0; l < 5; l++) {

              if (players[l][0] == jerseyNum) {

                 System.out.println("Enter a new jersey number: ");

                 players[l][0] = scan.nextInt();

                 System.out.println("Enter a rating for the new player: ");

                 players[l][1] = scan.nextInt();

              }

           }

           

        }

     }

     

     return;

  }

 

// this method take two parameters, players and min

// it then returns player with ratings greater than min

  public static void outputRoster(int[][] players, int min) {

     System.out.println(((min>0) ? ("ABOVE " + min) : ("ROSTER")));

     int item = 1;

     for (int[] player : players) {

        if (player[1] > min) {

           System.out.println("Player " + item + " -- Jersey number: " + player[0] + ", Rating: " + player[1]);

        }

        item++;

     }

     System.out.println();

  }

 

// outputMenu method to display the program menu

  public static void outputMenu() {

     System.out.println("MENU");

     System.out.println("u - Update player rating");

     System.out.println("a - Output players above a rating");

     System.out.println("r - Replace player");

     System.out.println("o - Output roster");

     System.out.println("q - Quit\n");

     System.out.println("Choose an option: ");  

  }

}

Explanation:

The program is written in Java and it is well commented.                                          

5 0
3 years ago
A. True
svetlana [45]

Answer : True  

Explanation: Vectors can hold, data of the same type and can automatically expand accordingly and change it’s size. The date stored in vectors should be linear.  

- The syntax for vector is vector<int>v;

- Mostly this is used in C++ as an alternative to arrays  

- If you want to use vector in your program then define it in the header first  i.e.

#include <vector>

- Push back is a function, that is used to insert an element into the vector  

- Pop back removes the element from the vector  


6 0
3 years ago
Assume that you have an array of integers named arr. Which of these code segments print the same results?
tresset_1 [31]

Answer:

II and III only

Explanation:

In Code segment II, the output of the array will be started form arr[0] and ends at the arr[length]. Because loop starts from 0 and ends at length of array. This will print the full array data.

In code segment III, the output will be all values of array as loop starts form first index and ends at last index.

On the other hand I code segment prints all array values except last value of the array. As the loop shows that, it will terminate at second last value of the array.

4 0
3 years ago
Me Completan Pliiiis
Brut [27]
Can you translate please i’ll help better
4 0
3 years ago
Why is Net WPM a better formula than Gross WPM to calculate typing speed?
Lelu [443]

Answer:

I think it is because a gross is equal to 144 and that is a hard way to count

Explanation:

7 0
2 years ago
Other questions:
  • Which operating system became obsolete with the arrival of a more advanced graphical user interfaces
    6·1 answer
  • A commonly used font style is _____. superscript periwinkle times new roman point
    7·1 answer
  • A(n _______________ is a pre-written formula that is built into excel
    12·1 answer
  • A computer lab has two printers. Printer I handles 40% of all the jobs. Its printing time is Exponential with the mean of 2 minu
    8·1 answer
  • How does LinkedIn differ from other popular social media platforms? What are the similarities?
    6·1 answer
  • What differentiates physical design from logical design?
    7·1 answer
  • What is one of the benefits of using templates for your email marketing campaigns?
    10·1 answer
  • write a program with total change amount as an integer input and output the change using the fewest coins, one coin type per lin
    8·1 answer
  • Write a function called play_round that simulates two people drawing cards and comparing their values. High card wins. In the ca
    11·1 answer
  • Which of the following is NOT a function of a Web Browser?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!