I have routes (route001 and route002). The user will select either one. I then need the code to recognise what route has been selected and change the start and directions variables accordingly (in the code below start and directions has the data for route001). I then want to run the function called vectors() on the route data that was selected.
I am unsure of how to change start and directions depending on what route the user selected.
I am also unsure how to call the function vectors() on the route data. I am not confident either that I have created the function correctly.
Any help would be much appreciated as I am very new to this.
route001 = (3, 12, 'S', 'S', 'W', 'S', 'S', 'S', 'E', 'E', 'E', 'S', 'S', 'W',
'W', 'S', 'E', 'E', 'E', 'E', 'N', 'N', 'N', 'N', 'W', 'N', 'N',
'E', 'E', 'S', 'E', 'S', 'E', 'S', 'S', 'W', 'S', 'S', 'S', 'S',
'S', 'E', 'N', 'E', 'E')
route002 = (12, 11, 'W', 'W', 'S', 'S', 'S', 'W', 'W', 'N', 'N', 'N', 'W', 'W',
'W', 'S', 'S', 'S', 'S', 'E', 'E', 'S', 'W', 'W', 'W', 'W', 'N', 'N',
'W', 'W', 'S', 'S', 'S', 'S', 'E', 'E', 'E', 'S', 'E', 'S', 'E', 'S')
start = [route001[0]] + [route001[1]]
directions = route001[2:]
coordinates = {"N": [0, 1], 'E': [1, 0], 'S': [0, -1], 'W': [-1, 0]}
def vectors():
for d in directions:
dx, dy = coordinates[d]
start[0] += dx
start[1] += dy
if start[0] < 0 or start[0] > 12:
print('Error: This route goes outside the grid')
break
elif start[1] < 0 or start[1] > 12:
print('Error: This route goes outside the grid')
break
else:
print(start)