https en wikipedia orgwikiohm27slaw apply ohm s law on any two given electrical values which can be voltage current and resistance and then in a python dict return namevalue pair of the zero value ohmslawvoltage10 resistance5 current0 current 2 0 ohmslawvoltage0 current0 resistance10 traceback most recent call last valueerror one and only one argument must be 0 ohmslawvoltage0 current1 resistance2 traceback most recent call last valueerror resistance cannot be negative ohmslawresistance0 voltage10 current1 resistance 10 0 ohmslawvoltage0 current1 5 resistance2 voltage 3 0 https en wikipedia org wiki ohm 27s_law apply ohm s law on any two given electrical values which can be voltage current and resistance and then in a python dict return name value pair of the zero value ohms_law voltage 10 resistance 5 current 0 current 2 0 ohms_law voltage 0 current 0 resistance 10 traceback most recent call last valueerror one and only one argument must be 0 ohms_law voltage 0 current 1 resistance 2 traceback most recent call last valueerror resistance cannot be negative ohms_law resistance 0 voltage 10 current 1 resistance 10 0 ohms_law voltage 0 current 1 5 resistance 2 voltage 3 0
from __future__ import annotations


def ohms_law(voltage: float, current: float, resistance: float) -> dict[str, float]:
    
    if (voltage, current, resistance).count(0) != 1:
        raise ValueError("One and only one argument must be 0")
    if resistance < 0:
        raise ValueError("Resistance cannot be negative")
    if voltage == 0:
        return {"voltage": float(current * resistance)}
    elif current == 0:
        return {"current": voltage / resistance}
    elif resistance == 0:
        return {"resistance": voltage / current}
    else:
        raise ValueError("Exactly one argument must be 0")


if __name__ == "__main__":
    import doctest

    doctest.testmod()