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

Function resistor_parallel

electronics/resistor_equivalence.py:6–28  ·  view source on GitHub ↗

Req = 1/ (1/R1 + 1/R2 + ... + 1/Rn) >>> resistor_parallel([3.21389, 2, 3]) 0.8737571620498019 >>> resistor_parallel([3.21389, 2, -3]) Traceback (most recent call last): ... ValueError: Resistor at index 2 has a negative or zero value! >>> resistor_parallel([3.21

(resistors: list[float])

Source from the content-addressed store, hash-verified

4
5
6def resistor_parallel(resistors: list[float]) -> float:
7 """
8 Req = 1/ (1/R1 + 1/R2 + ... + 1/Rn)
9
10 >>> resistor_parallel([3.21389, 2, 3])
11 0.8737571620498019
12 >>> resistor_parallel([3.21389, 2, -3])
13 Traceback (most recent call last):
14 ...
15 ValueError: Resistor at index 2 has a negative or zero value!
16 >>> resistor_parallel([3.21389, 2, 0.000])
17 Traceback (most recent call last):
18 ...
19 ValueError: Resistor at index 2 has a negative or zero value!
20 """
21
22 first_sum = 0.00
23 for index, resistor in enumerate(resistors):
24 if resistor <= 0:
25 msg = f"Resistor at index {index} has a negative or zero value!"
26 raise ValueError(msg)
27 first_sum += 1 / float(resistor)
28 return 1 / first_sum
29
30
31def resistor_series(resistors: list[float]) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected