Ejemplo n.º 1
0
    def multiply_numbers(self):
        """
            Multiplies 2 numbers read from the console in a given base and outputs the result

            Raises:
                ValueError: if either the number or the base is wrong
        """
        A = input("Introduceti numarul A: ")
        A = parse_to_bignumber(A)
        validate_number(A)

        B = input("Introduceti cifra B: ")
        B = parse_to_bignumber(B)
        validate_number(B)

        try:
            base = int(input("Introduceti baza pentru a efectua A * B: "))
        except ValueError:
            raise ValueError(
                "Baza trebuie sa fie din multimea {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}"
            )
        validate_base(base)

        self.print_delimiter()

        A = self.controller.convert_general(A, base)
        B = self.controller.convert_general(B, base)

        print(A, "*", B, "=", A * B)
Ejemplo n.º 2
0
    def convert_intermediary(self):
        """
            Converts a number to a given base using an intermediary base

            Raises:
                ValueError: if either the number or the base is wrong
        """
        A = input("Introduceti numarul A: ")
        A = parse_to_bignumber(A)
        validate_number(A)

        try:
            intermediary_base = int(input("Introduceti baza intermediara: "))
        except ValueError:
            raise ValueError(
                "Baza trebuie sa fie din multimea {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}"
            )
        validate_base(intermediary_base)

        try:
            base = int(input("Introduceti baza destinatie: "))
        except ValueError:
            raise ValueError(
                "Baza trebuie sa fie din multimea {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}"
            )
        validate_base(base)

        self.print_delimiter()

        self.controller.convert_intermediary(A, base, intermediary_base)
Ejemplo n.º 3
0
    def convert_general(self):
        """
            Converts a number to a given base in the most optimal approach

            Raises:
                ValueError: if either the number or the base is wrong
        """
        A = input("Introduceti numarul A: ")
        A = parse_to_bignumber(A)
        validate_number(A)

        try:
            base = int(input("Introduceti baza destinatie: "))
        except ValueError:
            raise ValueError(
                "Baza trebuie sa fie din multimea {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}"
            )
        validate_base(base)

        self.print_delimiter()

        self.controller.convert_general(A, base)
Ejemplo n.º 4
0
    def convert_fast(self):
        """
            Converts a number to a given base using the fast conversion method

            Raises:
                ValueError: if either the number or the base is wrong
                            if the number base or the destination base are not powers of 2
        """
        A = input("Introduceti numarul A: ")
        A = parse_to_bignumber(A)
        validate_number(A)

        try:
            base = int(input("Introduceti baza destinatie: "))
        except ValueError:
            raise ValueError(
                "Baza trebuie sa fie din multimea {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}"
            )
        validate_base(base)

        self.print_delimiter()

        self.controller.convert_fast(A, base)