diff --git a/BasicRegister.py b/bitutilities.py similarity index 51% rename from BasicRegister.py rename to bitutilities.py index 9e4801e..88577a5 100644 --- a/BasicRegister.py +++ b/bitutilities.py @@ -1,8 +1,29 @@ +def get_memory(variable_name: str) -> list[bool]: + """ + Reads user input to be used as a memory array. + + :param str variable_name: The name to be displayed in the input line. + + :return: A list of boolean values read from user. + :rtype: list[bool] + """ + while True: + input_chars: list[str] = list(input(f"Enter {variable_name}: ")) + + if all(character in ["0", "1"] for character in input_chars): + return [True if character == "1" else False for character in input_chars] + else: + print(f"[ERROR] The {variable_name} may contain only 1-s and 0-s!") class BasicRegister: + """The BasicRegister represents a hardware register capable of manipulating multiple bits at a time. + + :param list[bool] memory: The bits stored inside the register. + """ def __init__(self, memory: list[bool]): + """Constructor method""" self.memory: list[bool] = memory def __str__(self) -> str: diff --git a/main.py b/main.py index c1d0cbb..7fbf729 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,4 @@ -from BasicRegister import BasicRegister - - -def get_memory(variable_name: str) -> list[bool]: - while True: - input_chars: list[str] = list(input(f"Enter {variable_name}: ")) - - if all(character in ["0", "1"] for character in input_chars): - return [True if character == "1" else False for character in input_chars] - else: - print(f"[ERROR] The {variable_name} may contain only 1-s and 0-s!") +from bitutilities import * if __name__ == '__main__':