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

Function capacitor_parallel

electronics/capacitor_equivalence.py:6–23  ·  view source on GitHub ↗

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 inde

(capacitors: list[float])

Source from the content-addressed store, hash-verified

4
5
6def capacitor_parallel(capacitors: list[float]) -> float:
7 """
8 Ceq = C1 + C2 + ... + Cn
9 Calculate the equivalent resistance for any number of capacitors in parallel.
10 >>> capacitor_parallel([5.71389, 12, 3])
11 20.71389
12 >>> capacitor_parallel([5.71389, 12, -3])
13 Traceback (most recent call last):
14 ...
15 ValueError: Capacitor at index 2 has a negative value!
16 """
17 sum_c = 0.0
18 for index, capacitor in enumerate(capacitors):
19 if capacitor < 0:
20 msg = f"Capacitor at index {index} has a negative value!"
21 raise ValueError(msg)
22 sum_c += capacitor
23 return sum_c
24
25
26def capacitor_series(capacitors: list[float]) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected