Help with ring Bearer

I’m learning on python. So Ive done all that the code asked but I get an error saying that a value is not defined even though a previous function that is there by default should have defined it. here is my code “**” this will represent where the error is. here is also the link: CodeCombat - Coding games to learn Python and JavaScript?

def findSoldierOffset(soldiers, i):
    soldier = soldiers[i]
    angle = i * 360 / len(soldiers)
    return radialToCartesian(5, angle)

# This function does the math to determine the offset a soldier should stand at.
def radialToCartesian(radius, degrees):
    radians = Math.PI / 180 * degrees
    xOffset = radius * Math.cos(radians)
    yOffset = radius * Math.sin(radians)
    return {"x": xOffset, "y": yOffset}

peasant = hero.findByType("peasant")[0]
soldiers = hero.findByType("soldier")
# Use findByType to get an array of your soldiers.
while True:
    # Use a for-loop to iterate over range(len(soldiers)).
    
    for index in range(len(soldiers)):
        # Find the offset for a soldier.
        findSoldierOffset(soldiers, index)
        # Add the offset.x and offset.y to the peasant's pos.x and pos.y.
        newX = xOffset + peasant.pos.x
        newY = yOffset + peasant.pos.y
        # Command the soldier to move to the new offset position.
        hero.command(soldiers[index], "move", {"x": newX, "y": newY})
    # The hero should keep pace with the peasant!
    hero.move({"x": hero.pos.x + 0.2, "y": hero.pos.y})

not sure what I’m doing wrong but I’m eager to find out.

needs to be moved

this needs to be stored in a variable

newX / newY need to be the new variable.x / .y

This has been helpful however I’m not just there yet.
here is my code now

while True:
    # Use a for-loop to iterate over range(len(soldiers)).
    soldiers = hero.findByType("soldier")
    for index in range(len(soldiers)):
        # Find the offset for a soldier.
        offset = findSoldierOffset(soldiers, index)
        # Add the offset.x and offset.y to the peasant's pos.x and pos.y.
        newPos = offset.x + peasant.pos.x
        newPos = offset.y + peasant.pos.y
        # Command the soldier to move to the new offset position.
        hero.command(soldiers[index], "move", {"x": newPos.x, "y": newPos.y})
    # The hero should keep pace with the peasant!
    hero.move({"x": hero.pos.x + 0.2, "y": hero.pos.y})

the find soldiers command is in the loop now, and ive assigned a variable to the function and changed the new pos variable. however when I run the code: i get an error for the soldier movement code saying to target a number pos, when I remove the .x/.y it works but the soldiers don’t move properly and get stuck after some time. thank you for getting me closer, I need one last tip on what i’m doing wrong. I’ll see if I can do it myself in the meantime.