calculate the buoyant force of any body completely or partially submerged in a static fluid this principle was discovered by the greek mathematician archimedes equation for calculating buoyant force fb v g https en wikipedia orgwikiarchimedes27principle acceleration constant on earth unit ms2 args fluiddensity density of fluid kgm3 volume volume of objectliquid being displaced by the object m3 gravity acceleration from gravity gravitational force on the system the default is earth gravity returns the buoyant force on an object in newtons archimedesprinciplefluiddensity500 volume4 gravity9 8 19600 0 archimedesprinciplefluiddensity997 volume0 5 gravity9 8 4885 3 archimedesprinciplefluiddensity997 volume0 7 6844 061035 archimedesprinciplefluiddensity997 volume0 7 traceback most recent call last valueerror impossible object volume archimedesprinciplefluiddensity0 volume0 7 traceback most recent call last valueerror impossible fluid density archimedesprinciplefluiddensity997 volume0 7 gravity0 0 0 archimedesprinciplefluiddensity997 volume0 7 gravity9 8 traceback most recent call last valueerror impossible gravity acceleration constant on earth unit m s 2 also available in scipy constants g args fluid_density density of fluid kg m 3 volume volume of object liquid being displaced by the object m 3 gravity acceleration from gravity gravitational force on the system the default is earth gravity returns the buoyant force on an object in newtons archimedes_principle fluid_density 500 volume 4 gravity 9 8 19600 0 archimedes_principle fluid_density 997 volume 0 5 gravity 9 8 4885 3 archimedes_principle fluid_density 997 volume 0 7 6844 061035 archimedes_principle fluid_density 997 volume 0 7 traceback most recent call last valueerror impossible object volume archimedes_principle fluid_density 0 volume 0 7 traceback most recent call last valueerror impossible fluid density archimedes_principle fluid_density 997 volume 0 7 gravity 0 0 0 archimedes_principle fluid_density 997 volume 0 7 gravity 9 8 traceback most recent call last valueerror impossible gravity
g = 9.80665  


def archimedes_principle(
    fluid_density: float, volume: float, gravity: float = g
) -> float:
    

    if fluid_density <= 0:
        raise ValueError("Impossible fluid density")
    if volume <= 0:
        raise ValueError("Impossible object volume")
    if gravity < 0:
        raise ValueError("Impossible gravity")

    return fluid_density * gravity * volume


if __name__ == "__main__":
    import doctest

    doctest.testmod()