Skip to content

Ohm's Law algorithm added #3934

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 17 commits into from
Nov 25, 2020
Merged
32 changes: 32 additions & 0 deletions electronics/ohms_law.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Importing doctest for testing our function
from doctest import testmod

# Defining function


def ohms_law(voltage: float, current: float, resistance: float) -> float:

"""
This function calculates the any one
of the three ohms_law values voltage,
current, resistance, of electronics.
>>> ohms_law(voltage=10, resistance=5,current=0 )
2.0
>>> ohms_law(current=1, resistance=10, voltage=0)
10.0
"""
if voltage == 0:
result = float(current * resistance)
return result
elif current == 0:
result = voltage / resistance
return result
elif resistance == 0:
result = voltage / current
return result
else:
return 0


if __name__ == "__main__":
testmod(name="ohms_law", verbose=True)