Skip to content

Create calculate_resistence_in_series.py #7834

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 2 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
20 changes: 20 additions & 0 deletions electronics/calculate_resistence_in_series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resistors_in_series = [100, 150, 330]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a test variable, so it should be inside the doctest

Suggested change
resistors_in_series = [100, 150, 330]



def calculate_resistence_in_series(resistors_in_series: list) -> float:
"""
Calculate total resistance of resistors used in series

>>> calculate_resistence_in_series(resistors_in_series)
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
>>> calculate_resistence_in_series(resistors_in_series)
>>> calculate_resistence_in_series([100, 150, 330])

580
"""
total = 0
for val in resistors_in_series:
total = total + val
return total
Comment on lines +11 to +14
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
total = 0
for val in resistors_in_series:
total = total + val
return total
return sum(resistors_in_series)



if __name__ == "__main__":
import doctest

doctest.testmod()