utils + parallel resistors calculator

This commit is contained in:
2025-12-13 17:00:15 +01:00
parent 6709df960d
commit fc3b0b79f7
4 changed files with 47 additions and 26 deletions

18
parallel_resistors.py Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/python
from utils import parse_resistors
def get_input():
raw_input_resistors = input("Enter resistor values separated by spaces or commas: ")
resistors = parse_resistors(raw_input_resistors)
return resistors
def calculate_resistance(resistors):
return 1 / sum(1 / r for r in resistors)
if __name__ == '__main__':
try:
resistors = get_input()
except ValueError as e:
print(e)
exit(1)
print(f"Total resistance = {calculate_resistance(resistors)} ohms")