Skip to content

Create calculate_resistence_in_parallel.py #7838

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

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
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
14 changes: 14 additions & 0 deletions electronics/calculate_resistence_in_parallel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def calculate_resistence_in_parallel(resistors_in_parallel: list) -> float:
"""
Calculate total resistance of resistors used in parallel
>>> calculate_resistence_in_parallel([200, 470, 220])
85.67
"""
total = sum(1 / val for val in resistors_in_parallel)
return round(1 / total, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return round(1 / total, 2)
return 1 / total

No point rounding the output

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't round it we will get crazy result like 85.66694283347141



if __name__ == "__main__":
import doctest

doctest.testmod()