mmishanchyk

Retake Exam - 14.02.2021 (problem2)

Jun 17th, 2021
914
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. n = int(input())
  2.  
  3. coins = 0
  4. matrix = []
  5. step_history = []
  6.  
  7. for row in range(n):
  8.     matrix.append([el for el in input().split()])
  9.  
  10. for row in range(n):
  11.     for col in range(n):
  12.         if matrix[row][col] == "P":
  13.             start_row = row
  14.             start_col = col
  15.  
  16. commands = input()
  17.  
  18. while commands:
  19.  
  20.     if commands == "up":
  21.         row = start_row - 1
  22.         col = start_col
  23.  
  24.         if row in range(n) and col in range(n):
  25.             next_point = matrix[row][col]
  26.  
  27.         if next_point != "X":
  28.             coins += int(next_point)
  29.             step_history.append([row, col])
  30.             if coins >= 100:
  31.                 print(f"You won! You've collected {coins} coins.")
  32.                 break
  33.         else:
  34.             print(f"Game over! You've collected {(coins // 2)} coins.")
  35.             break
  36.  
  37.     elif commands == "down":
  38.         row = start_row + 1
  39.         col = start_col
  40.         if row not in range(n) and col not in range(n):
  41.             pass
  42.         else:
  43.             next_point = matrix[row][col]
  44.  
  45.         if next_point != "X":
  46.             coins += int(next_point)
  47.             step_history.append([row, col])
  48.             if coins >= 100:
  49.                 print(f"You won! You've collected {coins} coins.")
  50.                 break
  51.         else:
  52.             print(f"Game over! You've collected {coins // 2} coins.")
  53.             break
  54.     elif commands == "left":
  55.         row = start_row
  56.         col = start_col - 1
  57.         if row not in range(n) and col not in range(n):
  58.             pass
  59.         else:
  60.             next_point = matrix[row][col]
  61.  
  62.         if next_point != "X":
  63.             coins += int(next_point)
  64.             step_history.append([row, col])
  65.             if coins >= 100:
  66.                 print(f"You won! You've collected {coins} coins.")
  67.                 break
  68.         else:
  69.             print(f"Game over! You've collected {coins // 2} coins.")
  70.             break
  71.     elif commands == "right":
  72.         row = start_row
  73.         col = start_col + 1
  74.         if row not in range(n) and col not in range(n):
  75.             pass
  76.         else:
  77.             next_point = matrix[row][col]
  78.  
  79.         if next_point != "X":
  80.             coins += int(next_point)
  81.             step_history.append([row, col])
  82.             if coins >= 100:
  83.                 print(f"You won! You've collected {coins} coins.")
  84.                 break
  85.         else:
  86.             print(f"Game over! You've collected {coins // 2} coins.")
  87.             break
  88.  
  89.     start_row = row
  90.     start_col = col
  91.  
  92.     commands = input()
  93.  
  94. print("Your path:")
  95. for el in step_history:
  96.     print(el)
  97.  
RAW Paste Data