title finding the value of either gravitational force one of the masses or distance provided that the other three parameters are given description newton s law of universal gravitation explains the presence of force of attraction between bodies having a definite mass situated at a distance it is usually stated as that every particle attracts every other particle in the universe with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between their centers the publication of the theory has become known as the first great unification as it marked the unification of the previously described phenomena of gravity on earth with known astronomical behaviors the equation for the universal gravitation is as follows f g mass1 mass2 distance2 source https en wikipedia orgwikinewton27slawofuniversalgravitation newton 1687 philosophi naturalis principia mathematica define the gravitational constant g and the function input parameters force magnitude in newtons mass1 mass in kilograms mass2 mass in kilograms distance distance in meters returns result dict name value pair of the parameter having zero as it s value returns the value of one of the parameters specified as 0 provided the values of other parameters are given gravitationallawforce0 mass15 mass210 distance20 force 8 342875e12 gravitationallawforce7367 382 mass10 mass274 distance3048 mass1 1 385816317292268e19 gravitationallawforce36337 283 mass10 mass20 distance35584 traceback most recent call last valueerror one and only one argument must be 0 gravitationallawforce36337 283 mass1674 mass20 distance35584 traceback most recent call last valueerror mass can not be negative gravitationallawforce847938e12 mass1674 mass20 distance9374 traceback most recent call last valueerror gravitational force can not be negative run doctest define the gravitational constant g and the function unit of g m 3 kg 1 s 2 input parameters force magnitude in newtons mass_1 mass in kilograms mass_2 mass in kilograms distance distance in meters returns result dict name value pair of the parameter having zero as it s value returns the value of one of the parameters specified as 0 provided the values of other parameters are given gravitational_law force 0 mass_1 5 mass_2 10 distance 20 force 8 342875e 12 gravitational_law force 7367 382 mass_1 0 mass_2 74 distance 3048 mass_1 1 385816317292268e 19 gravitational_law force 36337 283 mass_1 0 mass_2 0 distance 35584 traceback most recent call last valueerror one and only one argument must be 0 gravitational_law force 36337 283 mass_1 674 mass_2 0 distance 35584 traceback most recent call last valueerror mass can not be negative gravitational_law force 847938e12 mass_1 674 mass_2 0 distance 9374 traceback most recent call last valueerror gravitational force can not be negative run doctest
from __future__ import annotations


GRAVITATIONAL_CONSTANT = 6.6743e-11  


def gravitational_law(
    force: float, mass_1: float, mass_2: float, distance: float
) -> dict[str, float]:
    

    product_of_mass = mass_1 * mass_2

    if (force, mass_1, mass_2, distance).count(0) != 1:
        raise ValueError("One and only one argument must be 0")
    if force < 0:
        raise ValueError("Gravitational force can not be negative")
    if distance < 0:
        raise ValueError("Distance can not be negative")
    if mass_1 < 0 or mass_2 < 0:
        raise ValueError("Mass can not be negative")
    if force == 0:
        force = GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
        return {"force": force}
    elif mass_1 == 0:
        mass_1 = (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_2)
        return {"mass_1": mass_1}
    elif mass_2 == 0:
        mass_2 = (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_1)
        return {"mass_2": mass_2}
    elif distance == 0:
        distance = (GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
        return {"distance": distance}
    raise ValueError("One and only one argument must be 0")



if __name__ == "__main__":
    import doctest

    doctest.testmod()