Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_valid(i: int):
- return 0 <= i < size
- size = int(input())
- matrix = [[int(x) for x in input().split()] for _ in range(size)]
- while True:
- command = input()
- if command == 'END':
- break
- tokens = command.split()
- row = int(tokens[1])
- col = int(tokens[2])
- value = int(tokens[3])
- if tokens[0] == 'Add':
- if is_valid(row) and is_valid(col):
- matrix[row][col] += value
- else:
- print('Invalid coordinates')
- elif tokens[0] == 'Subtract':
- if is_valid(row) and is_valid(col):
- matrix[row][col] -= value
- else:
- print('Invalid coordinates')
- [print(' '.join(map(str, x))) for x in matrix]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement