Advertisement
go6odn28

Matrix

Nov 27th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. rows, columns = [int(x) for x in input().split(", ")]
  2. matrix = []
  3. total_sum = 0
  4.  
  5. for _ in range(rows):
  6.     numbers = [int(x) for x in input().split(", ")]
  7.     matrix.append(numbers)
  8.  
  9. for row in range(rows):
  10.     for column in range(columns):
  11.         total_sum += matrix[row][column]
  12.  
  13. print(total_sum)
  14. print(matrix)
  15.  
  16. # COndition:
  17. #Write a program that reads a matrix from the console and prints:
  18. # •   The sum of all numbers in the matrix
  19. # •   The matrix itself
  20. # On the first line, you will receive the matrix sizes in the format "{rows}, {columns}". On the next rows, you will get elements for each column separated by a comma and a space ", ".
  21. #
  22. # Input:
  23. # 3, 6
  24. # 7, 1, 3, 3, 2, 1
  25. # 1, 3, 9, 8, 5, 6
  26. # 4, 6, 7, 9, 1, 0
  27. #
  28. # Output:
  29. # 76
  30. # [[7, 1, 3, 3, 2, 1], [1, 3, 9, 8, 5, 6], [4, 6, 7, 9, 1, 0]]
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement