Example #1
0
def main():

    while True:

        user_operation = GetNumbers()
        operator = user_operation.get_operator()

        get_x = GetNumbers()
        x = get_x.get_x()

        get_y = GetNumbers()
        y = get_y.get_y()

        if operator == 'a':
            add = Operations(x, y)
            add_result = round(add.addition(), 2)
            add_print = PrintResults(add_result)
            print(add_print.printed_string())
            print()

        elif operator == 's':
            subtract = Operations(x, y)
            sub_result = round(subtract.subtraction(), 2)
            sub_print = PrintResults(sub_result)
            print(sub_print.printed_string())
            print()

        elif operator == 'm':
            multiply = Operations(x, y)
            multiply_result = round(multiply.multiplication(), 2)
            multiply_print = PrintResults(multiply_result)
            print(multiply_print.printed_string())
            print()

        elif operator == 'd':
            divide = Operations(x, y)
            try:
                div_result = round(divide.division(), 2)
                div_print = PrintResults(div_result)
                print(div_print.printed_string())
            except TypeError:
                print(f"You can't divide zero by zero, that's just ludicrous!")
            print()
Example #2
0
    def test_addition(self):
        add_positive_ints = Operations(36, 45)
        add_negative_ints = Operations(-5, -9)
        add_positive_and_negative_ints = Operations(10, -8)
        add_positive_floats = Operations(42.0, 5.3)
        add_negative_floats = Operations(-85.6, -37.9)
        add_positive_and_negative_floats = Operations(54.1, -12.2)

        assert round(add_positive_ints.addition(), 2) == 81
        assert round(add_negative_ints.addition(), 2) == -14
        assert round(add_positive_and_negative_ints.addition(), 2) == 2
        assert round(add_positive_floats.addition(), 2) == 47.3
        assert round(add_negative_floats.addition(), 2) == -123.5
        assert round(add_positive_and_negative_floats.addition(), 2) == 41.9
Example #3
0
 def test_operation_addition(self):
     operation = Operations(100, 100)
     self.assertEqual(operation.addition(), 200, 'Incorrect result')