MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / capacitor_series

Function capacitor_series

electronics/capacitor_equivalence.py:26–47  ·  view source on GitHub ↗

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.713

(capacitors: list[float])

Source from the content-addressed store, hash-verified

24
25
26def capacitor_series(capacitors: list[float]) -> float:
27 """
28 Ceq = 1/ (1/C1 + 1/C2 + ... + 1/Cn)
29 >>> capacitor_series([5.71389, 12, 3])
30 1.6901062252507735
31 >>> capacitor_series([5.71389, 12, -3])
32 Traceback (most recent call last):
33 ...
34 ValueError: Capacitor at index 2 has a negative or zero value!
35 >>> capacitor_series([5.71389, 12, 0.000])
36 Traceback (most recent call last):
37 ...
38 ValueError: Capacitor at index 2 has a negative or zero value!
39 """
40
41 first_sum = 0.0
42 for index, capacitor in enumerate(capacitors):
43 if capacitor <= 0:
44 msg = f"Capacitor at index {index} has a negative or zero value!"
45 raise ValueError(msg)
46 first_sum += 1 / capacitor
47 return 1 / first_sum
48
49
50if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected