https en m wikipedia orgwikielectricpower this function can calculate any one of the three voltage current power fundamental value of electrical system examples are below electricpowervoltage0 current2 power5 resultname voltage value2 5 electricpowervoltage2 current2 power0 resultname power value4 0 electricpowervoltage2 current3 power0 resultname power value6 0 electricpowervoltage2 current4 power2 traceback most recent call last valueerror only one argument must be 0 electricpowervoltage0 current0 power2 traceback most recent call last valueerror only one argument must be 0 electricpowervoltage0 current2 power4 traceback most recent call last valueerror power cannot be negative in any electricalelectronics system electricpowervoltage2 2 current2 2 power0 resultname power value4 84 https en m wikipedia org wiki electric_power this function can calculate any one of the three voltage current power fundamental value of electrical system examples are below electric_power voltage 0 current 2 power 5 result name voltage value 2 5 electric_power voltage 2 current 2 power 0 result name power value 4 0 electric_power voltage 2 current 3 power 0 result name power value 6 0 electric_power voltage 2 current 4 power 2 traceback most recent call last valueerror only one argument must be 0 electric_power voltage 0 current 0 power 2 traceback most recent call last valueerror only one argument must be 0 electric_power voltage 0 current 2 power 4 traceback most recent call last valueerror power cannot be negative in any electrical electronics system electric_power voltage 2 2 current 2 2 power 0 result name power value 4 84
from __future__ import annotations

from typing import NamedTuple


class Result(NamedTuple):
    name: str
    value: float


def electric_power(voltage: float, current: float, power: float) -> tuple:
    
    if (voltage, current, power).count(0) != 1:
        raise ValueError("Only one argument must be 0")
    elif power < 0:
        raise ValueError(
            "Power cannot be negative in any electrical/electronics system"
        )
    elif voltage == 0:
        return Result("voltage", power / current)
    elif current == 0:
        return Result("current", power / voltage)
    elif power == 0:
        return Result("power", float(round(abs(voltage * current), 2)))
    else:
        raise ValueError("Exactly one argument must be 0")


if __name__ == "__main__":
    import doctest

    doctest.testmod()