def on_btn_z_add_released(self): try: z1 = self.get_z_z(1) z2 = self.get_z_z(2) result = integer.ADD_ZZ_Z(z1, z2) self.add_history_record('%d + %d = %d' % ( common.Z_to_num(z1), common.Z_to_num(z2), common.Z_to_num(result), )) except Exception as e: self.on_exception(e)
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]) # Сокращаем полученную дробь
def open_window_int_sum(): layout = [[sg.Text('Enter two integers')], [sg.Input(key='dig1')], [sg.Button('+', key='start')], [sg.Input(key='dig2')], [sg.Text(size=(400, 10), key='out')]] window = sg.Window('The sum of integer numbers', layout, size=(460, 260), resizable=True) while True: event, values = window.read() if event == "start": window['out'].update( ListToStr( integer.ADD_ZZ_Z(StrToList(values['dig1']), StrToList(values['dig2'])))) if event == sg.WINDOW_CLOSED: break
def test_negative_both(self): number1 = [1, 2, [4, 5]] number2 = [1, 2, [9, 9]] expect = [1, 3, [3, 5, 1]] result = integer.ADD_ZZ_Z(number1, number2) self.assertEqual(result, expect)
def test_negative_second(self): number1 = [0, 2, [4, 5]] number2 = [1, 2, [9, 9]] expect = [1, 2, [5, 4]] result = integer.ADD_ZZ_Z(number1, number2) self.assertEqual(result, expect)
def test_positive(self): number1 = [0, 2, [4, 5]] number2 = [0, 2, [9, 9]] expect = [0, 3, [3, 5, 1]] result = integer.ADD_ZZ_Z(number1, number2) self.assertEqual(result, expect)
def test_zero(self): number = [1, 2, [3, 5]] zero = [0, 1, [0]] expect = number result = integer.ADD_ZZ_Z(number, zero) self.assertEqual(result, expect)
def test_zeros(self): zero = [0, 1, [0]] expect = zero result = integer.ADD_ZZ_Z(zero, zero) self.assertEqual(result, expect)