[Solved] Why is my code miscalculating the total force from a list of (magnitude, angle) pairs? [closed]


from math import sqrt, sin, cos, atan2, degrees, radians

def find_net_force(forces):
    h_force = sum(
            [
                force[0] * 
                cos(radians(force[1])) for force in forces
            ]
    )
    v_force = sum(
            [
                force[0] * 
                sin(radians(force[1])) for force in forces
            ]
    )
    
    r_force = round(sqrt((h_force ** 2) + (v_force ** 2)), 1)
    r_angle = round(degrees(atan2(v_force, h_force)), 1)
    
    return (r_force, r_angle)
    
forces = [(10, 90), (10, -90), (100, 45), (20, 180)]
print(find_net_force(forces))

Try this one. I used list comprehension.

solved Why is my code miscalculating the total force from a list of (magnitude, angle) pairs? [closed]