https farside ph utexas eduteaching316lecturesnode46 html ceq c1 c2 cn calculate the equivalent resistance for any number of capacitors in parallel capacitorparallel5 71389 12 3 20 71389 capacitorparallel5 71389 12 3 traceback most recent call last valueerror capacitor at index 2 has a negative value ceq 1 1c1 1c2 1cn capacitorseries5 71389 12 3 1 6901062252507735 capacitorseries5 71389 12 3 traceback most recent call last valueerror capacitor at index 2 has a negative or zero value capacitorseries5 71389 12 0 000 traceback most recent call last valueerror capacitor at index 2 has a negative or zero value https farside ph utexas edu teaching 316 lectures node46 html ceq c1 c2 cn calculate the equivalent resistance for any number of capacitors in parallel capacitor_parallel 5 71389 12 3 20 71389 capacitor_parallel 5 71389 12 3 traceback most recent call last valueerror capacitor at index 2 has a negative value ceq 1 1 c1 1 c2 1 cn capacitor_series 5 71389 12 3 1 6901062252507735 capacitor_series 5 71389 12 3 traceback most recent call last valueerror capacitor at index 2 has a negative or zero value capacitor_series 5 71389 12 0 000 traceback most recent call last valueerror capacitor at index 2 has a negative or zero value
from __future__ import annotations


def capacitor_parallel(capacitors: list[float]) -> float:
    
    sum_c = 0.0
    for index, capacitor in enumerate(capacitors):
        if capacitor < 0:
            msg = f"Capacitor at index {index} has a negative value!"
            raise ValueError(msg)
        sum_c += capacitor
    return sum_c


def capacitor_series(capacitors: list[float]) -> float:
    

    first_sum = 0.0
    for index, capacitor in enumerate(capacitors):
        if capacitor <= 0:
            msg = f"Capacitor at index {index} has a negative or zero value!"
            raise ValueError(msg)
        first_sum += 1 / capacitor
    return 1 / first_sum


if __name__ == "__main__":
    import doctest

    doctest.testmod()