Need help with understanding returns

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}

In the code above I am having trouble. On the second function, it ends with a return statement but I am confused about were the {β€œx”: xOffset, β€œy”: yOffset} goes. Because I need that return value in a var the level an I don’t know where the return value goes.
Level is Ringer Bearer btw.

3 Likes

The return goes when you call the function. So if you call radialToCartesian and you put in the parameters, it will give you back this dictionary.

So if you want to use it, you assign it to a variable: cartesian = radialToCartesian(radius, degrees)
if you do hero.say(cartesian) it should give you the dictionary.

1 Like