Case10. The robot can move in four directions ("N" - north, "W" - west, "S" - South, "E" - east) and take three digital commands: 0 - continue movement, 1 - turn left, -1 - turn right. The symbol D is the initial direction of the robot and the integer N is the command sent to it. Output the direction of the robot after the command is executed.

Solution in Python 3:

import random

M = random.randrange(1,13)
#M=12
d = {'N' : 'North', 'W' : 'West', 'S' : 'South', 'E' : 'East'}
r = {-1 : "turn right", 0 : "continue movement", 1 : "turn left"}
d1 = {0 : 'N', 1: 'W', 2 : 'S', 3 : 'E'}
try:
i = random.randrange(0,4)
#print("i : ", i)
#print("d1 : ", d1[i])
#print("d : ", d[d1[i]])
C = d[d1[i]]
print("Initial direction (C) : ", C)
N = random.randrange(-1,2)
print("Command (N) : ", N)
print("Turn: ", r[N])
if N == -1:
print("Part -1")
if i == 0:
i = 3
#print("Part ", d[d1[i]])
elif i == 3:
i = 2
#print("Part ", d[d1[i]])
elif i == 2:
i = 1
#print("Part ", d[d1[i]])
elif i == 1:
i == 0
#print("Part ", d[d1[i]])
elif N == 1:
#print("Part -1")
if i == 0:
i = 1
elif i == 1:
i = 2
elif i == 2:
i = 3
elif i == 3:
d1 = 0
C = d[d1[i]]
print("New direction (C) : ", C)
except KeyError as e:
print('Error')