Skip to content

Created equivalent_resistance under Electronics #6782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update resistor_equivalence.py
  • Loading branch information
cclauss authored Oct 30, 2022
commit 4bb0d90dc4104bcfad283ccb7aa58a534275e99e
15 changes: 8 additions & 7 deletions electronics/resistor_equivalence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from __future__ import annotations


def resistor_parallel(
resistors: list[float],
) -> float: # Req = 1/ (1/R1 + 1/R2 + ... + 1/Rn)
def resistor_parallel(resistors: list[float]) -> float:
"""
Req = 1/ (1/R1 + 1/R2 + ... + 1/Rn)

>>> resistor_parallel([3.21389, 2, 3])
0.8737571620498019
>>> resistor_parallel([3.21389, 2, -3])
Expand All @@ -29,10 +29,12 @@ def resistor_parallel(
return 1 / first_sum


def resistor_series(resistors: list[float]) -> float: # Req = R1 + R2 + ... + Rn
def resistor_series(resistors: list[float]) -> float:
"""
This function can calculate the equivalent resistance for any number of
resistors in parallel.
Req = R1 + R2 + ... + Rn

Calculate the equivalent resistance for any number of resistors in parallel.

>>> resistor_series([3.21389, 2, 3])
8.21389
>>> resistor_series([3.21389, 2, -3])
Expand All @@ -43,7 +45,6 @@ def resistor_series(resistors: list[float]) -> float: # Req = R1 + R2 + ... + R
sum_r = 0.00
index = 0
for resistor in resistors:

sum_r += resistor
if resistor < 0:
raise ValueError(f"Resistor at index {index} has a negative value!")
Expand Down