# 02. Fishing Competition

Jun 18th, 2024
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def directions(position, direction, rows):
2.     row, col = position
3.     if direction == "up":
4.         row = (row - 1) % rows
5.     elif direction == "down":
6.         row = (row + 1) % rows
7.     elif direction == "left":
8.         col = (col - 1) % rows
9.     elif direction == "right":
10.         col = (col + 1) % rows
11.
12.     return row, col
13.
14.
15. def print_matrix(matrix):
16.     for row in matrix:
17.         print("".join(row))
18.
19.
20. rows = int(input())
21. fishing_area = []
22. captain, whirlpool, empty, passage, quota = "S", "W", "-", 0, 20
23. position = None
24.
25. for row_ in range(rows):
26.     line = list(input())
27.     if captain in line:
28.         position = (row_, line.index(captain))
29.     fishing_area.append(line)
30.
31. direction = input()
32.
33. while direction != "collect the nets":
34.     new_position = directions(position, direction, rows)
35.     n_row, n_col = new_position
36.
37.     step = fishing_area[n_row][n_col]
38.
39.     if step.isdigit():
40.         passage += int(step)
41.
42.     if step == whirlpool:
43.         passage = 0
44.         print(f"You fell into a whirlpool! The ship sank and you lost the fish you caught. "
45.               f"Last coordinates of the ship: [{n_row},{n_col}]")
46.         exit()
47.
48.     fishing_area[position[0]][position[1]] = empty
49.     fishing_area[n_row][n_col] = captain
50.     position = new_position
51.     direction = input()
52.
53. if passage >= quota:
54.     print(f"Success! You managed to reach the quota!")
55. else:
56.     print(f"You didn't catch enough fish and didn't reach the quota! You need {quota - passage} tons of fish more.")
57.
58. print(f"Amount of fish caught: {passage} tons.")
59.
60. print_matrix(fishing_area)