add type hints

This commit is contained in:
Spy 2022-10-12 17:15:42 +01:00
parent 41f07e766c
commit cee745fd39

10
main.py
View File

@ -2,14 +2,14 @@ from json import load as json_load
import colours as c import colours as c
def load_json(file_name): def load_json(file_name: str) -> dict:
# Open a json file called file_name # Open a json file called file_name
with open(file_name) as file: with open(file_name) as file:
# Load the json file into a dictionary # Load the json file into a dictionary
return json_load(file) return json_load(file)
def convert(value): def convert(value: int):
if 1000 <= value < 1000000: if 1000 <= value < 1000000:
# Kilo # Kilo
value = str(value / 1000) + " K" value = str(value / 1000) + " K"
@ -25,7 +25,7 @@ def convert(value):
return value return value
def input_colours(bands): def input_colours(bands: dict) -> list:
colours = [] colours = []
while len(colours) < 5: while len(colours) < 5:
# Calculate a suffix for the number i.e. 2nd or 3rd # Calculate a suffix for the number i.e. 2nd or 3rd
@ -52,7 +52,7 @@ def input_colours(bands):
return colours return colours
def calc_resistor(colours, bands): def calc_resistor(colours: list, bands: dict) -> (float | int, float | int):
# Set default values # Set default values
bands_value = "" bands_value = ""
multiplier = 1 multiplier = 1
@ -76,7 +76,7 @@ def calc_resistor(colours, bands):
return resistor_value, tolerance return resistor_value, tolerance
def main(file_name): def main(file_name: str):
# Print the welcome message # Print the welcome message
print(f"{c.magenta}Resistor Calculator{c.end}") print(f"{c.magenta}Resistor Calculator{c.end}")