I am trying to write a program which takes a list of directions and magnitudes and outputs the distance of the robot from its starting position.
I get an error when executing the following code but I cannot identify why I get the error.
import math
position = [0,0]
direction = ['+Y','-X','-Y','+X','-X','-Y','+X']
magnitude = [9,7,4,8,3,6,2]
i = 0
while i < len(direction):
if direction[i] == '+Y': position[0] += magnitude[i]
elif direction[i] == '-Y': position[0] -= magnitude[i]
elif direction[i] == '+X': position[1] += magnitude[i]
elif direction[i] == '-X': position[1] -= magnitude[i]
else: pass
i += 1
print float(math.sqrt(position[1]**2+position[0]**2))
Edit:
I get this error:
IndentationError: unindent does not match any outer indentation level