Advertisement
qwerty199991

Марсоход

May 27th, 2022
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. vect = 0
  2. x = 0
  3. y = 0
  4. f = open('instructions.txt', "r")
  5.  
  6. def move(step:int):
  7.     global x,y
  8.     if vect == 0:
  9.         x += step
  10.     if vect == 90:
  11.         y += step
  12.     if vect == 180:
  13.         x -= step
  14.     if vect == 270:
  15.         y -= step
  16.    
  17.        
  18. def turn(where):
  19.     global vect
  20.     if where == 'left':
  21.         vect -= 90
  22.     else:
  23.         vect += 90
  24.        
  25.     if vect == -90:
  26.         vect == 270
  27.     if vect == 420:
  28.         vect == 90
  29.     if vect == 360:
  30.         vect == 0
  31.  
  32. for line in f:
  33.     spl = line.lower().split()
  34.     if len(spl) > 1:
  35.         move(int(spl[1]))
  36.     elif (spl[0] == 'left') or (spl[0] == 'right'):
  37.         turn(line)
  38.     elif spl[0] == 'stop':
  39.         print()
  40.        
  41.        
  42. if (x,y) == (0,0):
  43.     print(0)
  44. if (x,y) == (1,0):
  45.     print(1)
  46. if (x,y) == (2,0):
  47.     print(2)
  48. if (x,y) == (3,0):
  49.     print(3)
  50. if (x,y) == (0,1):
  51.     print(4)
  52. if (x,y) == (0,-1):
  53.     print(5)
  54.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement