diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index 3529a09339c4..9383ec7e5b01 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -6,13 +6,22 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float ) -> float: """ - 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| - --------------- + Wheatstone Bridge is an electrical circuit used to accurately measure + an unknown resistance by balancing two legs of a bridge circuit. + + The bridge is said to be balanced when no current flows + through the galvanometer connected between the midpoints + of the two voltage dividers. + Balance condition: + R1 / R2 = R3 / R4 + + Applications: + - Measurement of unknown resistance + - Strain gauge circuits + - Sensor calibration + This function can calculate the unknown resistance in an wheatstone + network, given that the three other resistances + in the network are known. Usage examples: >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5) diff --git a/strings/count_vowels_consonants.py b/strings/count_vowels_consonants.py new file mode 100644 index 000000000000..7486ee0cf9be --- /dev/null +++ b/strings/count_vowels_consonants.py @@ -0,0 +1,34 @@ +def count_vowels_and_consonants(text: str) -> tuple[int, int]: + """ + Count the number of vowels and consonants in a given string. + + This function ignores non-alphabetic characters. + + Args: + text (str): Input string. + + Returns: + tuple[int, int]: A tuple containing (vowel_count, + consonant_count). + Examples: + >>> count_vowels_and_consonants("Hello World") + (3, 7) + >>> count_vowels_and_consonants("AEIOU") + (5, 0) + >>> count_vowels_and_consonants("bcdf") + (0, 4) + >>> count_vowels_and_consonants("") + (0, 0) + """ + vowels = set("aeiouAEIOU") + vowel_count = 0 + consonant_count = 0 + + for char in text: + if char.isalpha(): + if char in vowels: + vowel_count += 1 + else: + consonant_count += 1 + + return vowel_count, consonant_count