Skip to content

Commit 504a4d3

Browse files
committed
Redid 2.Multidimensional Lists - Exercise
1 parent 0ee0c44 commit 504a4d3

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
matrix = input().split("|")
1+
matrix = [nums.split() for nums in input().split("|")]
2+
[[print(value, end=" ") for value in lst] for lst in matrix[::-1]]
23

3-
matrix = [char.split() for char in matrix]
44

5-
[[print(value, end=" ") for value in lst] for lst in matrix[::-1]]
5+
# [[print(value, end=" ") for value in lst] for lst in [nums.split() for nums in input().split("|")][::-1]]
Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,63 @@
11
rows = int(input())
22

3-
matrix = []
3+
matrix = [
4+
[int(num) for num in input().split()]
5+
for row in range(rows)
6+
]
47

5-
for row in range(rows):
6-
columns = [int(num) for num in input().split()]
7-
matrix.append(columns)
8+
command = input()
9+
while command != "END":
10+
try:
811

9-
command = input().split()
10-
while command[0] != "END":
12+
operation, row, col, value = command.split()
13+
row, col, value = int(row), int(col), int(value)
1114

12-
row = int(command[1])
13-
col = int(command[2])
14-
value = int(command[3])
15+
if row >= 0 and col >= 0:
1516

16-
if 0 <= row < len(matrix) and 0 <= col < len(matrix[row]):
17+
if operation == "Add":
18+
matrix[row][col] += value
1719

18-
if command[0] == "Add":
19-
matrix[row][col] += value
20+
elif operation == "Subtract":
21+
matrix[row][col] -= value
2022

21-
elif command[0] == "Subtract":
22-
matrix[row][col] -= value
23+
else:
24+
print("Invalid coordinates")
2325

24-
else:
25-
print("Invalid coordinates")
26-
27-
command = input().split()
26+
command = input()
2827

29-
[print(*row) for row in matrix]
28+
except Exception:
29+
print("Invalid coordinates")
30+
command = input()
31+
32+
[print(" ".join([str(num) for num in line])) for line in matrix]
33+
34+
35+
# rows = int(input())
36+
#
37+
# matrix = []
38+
#
39+
# for row in range(rows):
40+
# columns = [int(num) for num in input().split()]
41+
# matrix.append(columns)
42+
#
43+
# command = input().split()
44+
# while command[0] != "END":
45+
#
46+
# row = int(command[1])
47+
# col = int(command[2])
48+
# value = int(command[3])
49+
#
50+
# if 0 <= row < len(matrix) and 0 <= col < len(matrix[row]):
51+
#
52+
# if command[0] == "Add":
53+
# matrix[row][col] += value
54+
#
55+
# elif command[0] == "Subtract":
56+
# matrix[row][col] -= value
57+
#
58+
# else:
59+
# print("Invalid coordinates")
60+
#
61+
# command = input().split()
62+
#
63+
# [print(*row) for row in matrix]

Advanced/2.Multidimensional Lists/2.Multidimensional Lists - Exercise/03. Knight Game.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
rows = int(input())
22

3-
pos_knights, matrix, total_knights = [], [], [0]
3+
pos_knights, matrix, total_knights = [], [], [0]
44

55
for row in range(rows):
66

77
matrix.append(list(input()))
88

99
for col in range(len(matrix[0])):
10-
10+
1111
if matrix[row][col] == "K":
1212
pos_knights.append([row, col])
1313

@@ -28,7 +28,6 @@ def check_valid_index(row, col):
2828

2929

3030
def check_knights():
31-
3231
knights = {}
3332

3433
for row, col in pos_knights:

0 commit comments

Comments
 (0)