Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = int(input("enter x position \n")) # taking input from user
- y = int(input("enter y position \n")) # for coordinates
- current = 0 # making default position of a robot
- instructions = input("enter instructions \n") # taking input from user for instructions
- instructions = instructions.upper() # used upper function so i don't
- # need to make extra statements
- for ins in instructions:
- assert (ins in "DLN ") # displaying error if instructions are invalid
- if ins == 'D':
- current = current - 1 # current position - 90 degrees c-clockwise
- elif ins == 'L':
- current = current + 1 # current position + 90 degrees c-clockwise
- elif ins == 'N':
- if current % 4 == 0: # 0 / 360 (position at the beginning)
- x = x + 1
- elif current % 4 == 1: # 90 degrees counter-clockwise
- y = y + 1
- elif current % 4 == 2: # 180 degrees counter-clockwise
- x = x - 1
- elif current % 4 == 3: # 270 degrees counter-clockwise
- y = y - 1
- print("x position is: %d" %x)
- print("y position is: %d" %y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement