ElenaSokol

Untitled

Oct 24th, 2022
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. size = int(input())
  2. racing_number = input()
  3. matrix = []
  4. tunel_pos = []
  5. distance = 0
  6.  
  7. for row in range(size):
  8.     line = input().split()
  9.     matrix.append(line)
  10.     if 'T' in line:
  11.         tunel_pos = [row, line.index('T')]
  12.  
  13. command = input()
  14. row, col = 0, 0
  15.  
  16. while 0 <= row < size and 0 <= col < size:
  17.  
  18.     if matrix[row][col] == "T":
  19.         distance += 20
  20.         tunel_pos = "."
  21.         matrix[row][col] = "."
  22.         temp = row
  23.         row = col
  24.         col = temp
  25.  
  26.     if matrix[row][col] == "F":
  27.         matrix[row][col] = "C"
  28.         print(f"Racing car {racing_number} finished the stage!")
  29.         break
  30.     if command == 'up':
  31.         row -= 1
  32.         distance += 10
  33.     elif command == 'down':
  34.         row += 1
  35.         distance += 10
  36.     elif command == 'left':
  37.         col -= 1
  38.         distance += 10
  39.     elif command == 'right':
  40.         col += 1
  41.         distance += 10
  42.     if command == "End":
  43.         print(f"Racing car {racing_number} DNF.")
  44.         break
  45.  
  46.     command = input()
  47.  
  48. if distance:
  49.     print(f"Distance covered {distance} km." )
  50. for m_line in matrix:
  51.     print("".join(m_line))
Advertisement
Add Comment
Please, Sign In to add comment