Files
electronics_scripts/parallel_resistors.py

19 lines
514 B
Python

#!/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")