From 04e96506401bda46fb7bd2e4800f21db29b3bcb7 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:51:55 +0530 Subject: [PATCH 1/3] Add files via upload --- electronics/wheatstone_bridge.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 electronics/wheatstone_bridge.py diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py new file mode 100644 index 000000000000..02aa9f6e05f1 --- /dev/null +++ b/electronics/wheatstone_bridge.py @@ -0,0 +1,36 @@ +# https://en.wikipedia.org/wiki/Wheatstone_bridge +from __future__ import annotations + + +def wheatstone_solver( + resistance_1: float, resistance_2: float, resistance_3: float +) -> tuple: + """ + This function can calculate the unknown resistance in an wheatstone network. + + Usage examples: + >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5) + 10.0 + >>> wheatstone_solver(resistance_1=356, resistance_2=234, resistance_3=976) + 641.5280898876405 + >>> wheatstone_solver(resistance_1=2, resistance_2=-1, resistance_3=2) + Traceback (most recent call last): + ... + ValueError: All resistance values must be positive + >>> wheatstone_solver(resistance_1=0, resistance_2=0, resistance_3=2) + Traceback (most recent call last): + ... + ValueError: All resistance values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0 or resistance_3 <= 0: + raise ValueError("All resistance values must be positive") + else: + return (resistance_2 / resistance_1) * resistance_3 + + +if __name__ == "__main__": + import doctest + + doctest.testmod() +# print(wheatstone_solver(356,234,976)) From 11cdfae20104cc0f75b3a0d6e0c3a411774ec75f Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:03:32 +0530 Subject: [PATCH 2/3] Update wheatstone_bridge.py --- electronics/wheatstone_bridge.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index 02aa9f6e05f1..a618855ae747 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -4,7 +4,7 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float -) -> tuple: +) -> float: """ This function can calculate the unknown resistance in an wheatstone network. @@ -26,11 +26,10 @@ def wheatstone_solver( if resistance_1 <= 0 or resistance_2 <= 0 or resistance_3 <= 0: raise ValueError("All resistance values must be positive") else: - return (resistance_2 / resistance_1) * resistance_3 + return float((resistance_2 / resistance_1) * resistance_3) if __name__ == "__main__": import doctest doctest.testmod() -# print(wheatstone_solver(356,234,976)) From dd1587ae8337392e05bf2a6d523d1c1698ae7d32 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:10:54 +0530 Subject: [PATCH 3/3] Update wheatstone_bridge.py --- electronics/wheatstone_bridge.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index a618855ae747..3529a09339c4 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -6,7 +6,13 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float ) -> float: """ - This function can calculate the unknown resistance in an wheatstone network. + This function can calculate the unknown resistance in an wheatstone network, + given that the three other resistances in the network are known. + The formula to calculate the same is: + + --------------- + |Rx=(R2/R1)*R3| + --------------- Usage examples: >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5)