示例#1
0
def DIV_ZZ_Z(x, y):
    # Савелий Гурьянов
    # Частное от деления целого на целое
    if POZ_Z_D(x) == POZ_Z_D(y):
        return nat.DIV_NN_N(ABS_Z_N(x), ABS_Z_N(y))
    elif nat.NZER_N_B(x) or nat.NZER_N_B(x):
        return ["Unable to calculate"]
    else:
        return ['-'] + nat.DIV_NN_N(ABS_Z_N(x), ABS_Z_N(y))
def ADD_QQ_Q(list1, list2):
    # Пекло Елизавета
    # Сложение дробей
    mul = nat.LCM_NN_N(list1[1], list2[1])  # НОК знаменателей
    mul1 = nat.DIV_NN_N(mul, list1[1])  # Сопряженное к первому знаменателю
    mul2 = nat.DIV_NN_N(mul, list2[1])  # Сопряженное ко второму знаменателю
    firstNum = integer.MUL_ZZ_Z(list1[0],
                                mul1)  # Первое слагаемое нового числителя
    secNum = integer.MUL_ZZ_Z(list2[0], mul2)  # Второе
    numerator = integer.ADD_ZZ_Z(firstNum,
                                 secNum)  # Числитель, как сумма этих слагаемых
    denominator = mul  # НОД знаменателей - новый знаменатель

    return RED_Q_Q([numerator, denominator])  # Сокращаем полученную дробь
示例#3
0
 def on_btn_n_divn_released(self):
     try:
         n1 = self.get_n_n(1)
         n2 = self.get_n_n(2)
         result = natural.DIV_NN_N(n1, n2)
         self.add_history_record('%d / %d = %d' % (
             common.N_to_num(n1),
             common.N_to_num(n2),
             common.N_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#4
0
def open_window_nat_quot():
    layout = [
        [sg.Text('Enter two naturals')],
        [sg.Input(key='dig1')],
        [sg.Button('/', key='start')],
        [sg.Input(key='dig2')],
        [sg.Text(size=(400, 10), key='out')]
    ]
    window = sg.Window('The quotient of natural numbers', layout, size=(460, 260), resizable=True)
    while True:
        event, values = window.read()
        if event == "start":
            window['out'].update(nat.DIV_NN_N(values['dig1'], values['dig2']))
        if event == sg.WINDOW_CLOSED:
            break
示例#5
0
 def test_normal(self):
     number1 = [5, [6, 5, 3, 6, 4]]
     number2 = [2, [8, 4]]
     expect = [3, [5, 6, 9]]
     result = natural.DIV_NN_N(number1, number2)
     self.assertEqual(result, expect)
示例#6
0
 def test_small(self):
     number1 = [2, [1, 2]]
     number2 = [2, [2, 2]]
     expect = [1, [0]]
     result = natural.DIV_NN_N(number1, number2)
     self.assertEqual(result, expect)
示例#7
0
 def test_equal(self):
     number = [3, [6, 2, 6]]
     expect = [1, [1]]
     result = natural.DIV_NN_N(number, number)
     self.assertEqual(result, expect)
示例#8
0
 def test_zero(self):
     zero = [1, [0]]
     number = [3, [6, 2, 6]]
     expect = [1, [0]]
     result = natural.DIV_NN_N(zero, number)
     self.assertEqual(result, expect)