Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def valid_idx(any_row, any_col, size):
- valid_range = range(0, size)
- if any_row in valid_range and any_col in valid_range:
- return True
- rows = int(input())
- matrix = []
- for row in range(rows):
- matrix.append([int(n) for n in input().split()])
- while True:
- command_line = input().split()
- if command_line[0] == "END":
- break
- command = command_line[0]
- r, c, value = [int(n) for n in command_line[1:]]
- if not valid_idx(r, c, rows):
- print("Invalid coordinates")
- continue
- if command == "Add":
- matrix[r][c] += value
- elif command == "Subtract":
- matrix[r][c] -= value
- for row in range(rows):
- print(*matrix[row])
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement