fork download
  1. import random
  2.  
  3. # Create a 4x4 two-dimensional list filled with random numbers
  4. rows, cols = 4, 4
  5. matrix = [[random.randint(0, 100) for _ in range(cols)] for _ in range(rows)]
  6.  
  7. # Print the matrix
  8. print("Matrix:")
  9. for row in matrix:
  10. print(row)
  11.  
  12. # Initialize variables to track the maximum value and its indexes
  13. max_value = float('-inf')
  14. max_index = (-1, -1)
  15.  
  16. # Iterate through the matrix to find the maximum value and its indexes
  17. for i in range(rows):
  18. for j in range(cols):
  19. if matrix[i][j] > max_value:
  20. max_value = matrix[i][j]
  21. max_index = (i, j)
  22.  
  23. # Print the maximum value and its indexes
  24. print(f"\nMaximum value: {max_value}")
  25. print(f"Indexes of maximum value: {max_index}")
Success #stdin #stdout 0.04s 9888KB
stdin
Standard input is empty
stdout
Matrix:
[97, 37, 36, 26]
[12, 63, 15, 23]
[19, 1, 61, 31]
[37, 65, 19, 33]

Maximum value: 97
Indexes of maximum value: (0, 0)