Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def directions(position, direction, rows, matrix):
- row, col = position
- matrix[row][col] = "-"
- if direction == "up":
- row = (row - 1) % rows
- elif direction == "down":
- row = (row + 1) % rows
- elif direction == "left":
- col = (col - 1) % rows
- elif direction == "right":
- col = (col + 1) % rows
- return row, col
- def print_matrix(matrix):
- for row in matrix:
- print("".join(row))
- rows = int(input())
- fishing_area = []
- captain, whirlpool, empty, passage, quota = "S", "W", "-", 0, 20
- position = None
- for row_ in range(rows):
- line = list(input())
- if captain in line:
- position = (row_, line.index(captain))
- fishing_area.append(line)
- direction = input()
- while direction != "collect the nets":
- new_position = directions(position, direction, rows,fishing_area)
- n_row, n_col = new_position
- step = fishing_area[n_row][n_col]
- if step.isdigit():
- passage += int(step)
- if step == whirlpool:
- passage = 0
- print(f"You fell into a whirlpool! The ship sank and you lost the fish you caught. "
- f"Last coordinates of the ship: [{n_row},{n_col}]")
- exit()
- fishing_area[n_row][n_col] = captain
- position = new_position
- direction = input()
- if passage >= quota:
- print(f"Success! You managed to reach the quota!")
- else:
- print(f"You didn't catch enough fish and didn't reach the quota! You need {quota - passage} tons of fish more.")
- if passage > 0:
- print(f"Amount of fish caught: {passage} tons.")
- print_matrix(fishing_area)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement