def robot_move(n, commands):
    x = 1
    y = 1

    for i in range(len(commands)):
        if commands[i] == "R" and x + 1 <= n:
            x += 1
        elif commands[i] == "L" and x - 1 >= 1:
            x -= 1
        elif commands[i] == "U" and y - 1 >= 1:
            y -= 1
        elif commands[i] == "D" and y + 1 <= n:
            y += 1

    return x, y

n = 5
commands = "RRRUDD"
print(robot_move(n, commands))

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: