Advertisement
limpingricky

fukin_robots2

May 28th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. x = int(input("enter x position \n"))          # taking input from user
  2. y = int(input("enter y position \n"))          # for coordinates
  3.  
  4. current = 0                                    # making default position of a robot
  5.  
  6. instructions = input("enter instructions \n")  # taking input from user for instructions
  7. instructions = instructions.upper()            # used upper function so i don't
  8.                                                # need to make extra statements
  9. for ins in instructions:
  10.     assert (ins in "DLN ")                     # displaying error if instructions are invalid
  11.     if ins == 'D':
  12.         current = current - 1                  # current position - 90 degrees c-clockwise
  13.     elif ins == 'L':
  14.         current = current + 1                  # current position + 90 degrees c-clockwise
  15.     elif ins == 'N':
  16.         if current % 4 == 0:                   # 0 / 360 (position at the beginning)
  17.             x = x + 1
  18.         elif current % 4 == 1:                 # 90 degrees counter-clockwise
  19.             y = y + 1
  20.         elif current % 4 == 2:                 # 180 degrees counter-clockwise
  21.             x = x - 1
  22.         elif current % 4 == 3:                 # 270 degrees counter-clockwise
  23.             y = y - 1
  24.  
  25. print("x position is: %d" %x)
  26. print("y position is: %d" %y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement