def matrix_print(matrix):
print(‘_______’)
for i in matrix:
for el in i:
print(el, end=’ ‘)
print()

matrix_2x2 = [[1, 2],
[3, 4]]

matrix_3x2 = [[32, 232],
[543, 134],
[565, 665]]

matrix_2x3 = [[1, 2, 3],
[4, 5, 6]]

def matrix_metric(matrix):
m = 0
n = 0
for rows in matrix:
m += 1
for elements in rows:
if elements > len(rows):
break
else:
n+=1
metric = (m,n)
return metric

def transpose_matrix(matrix):
metric = matrix_metric(matrix)
transposed=[]
for i in range(metric[1]):
column = []
transposed.append(column)

for i in range(metric[0]):
for c in range(len(transposed)):
transposed[c].append(matrix[i][c])
return transposed

def minor_matrix_i(matrix,m1,n1):

result = [row[:] for row in matrix]
for m in range(len(result)):
result[m].pop(n1)
result.pop(m1)
m_sum= 0
return result


def minor_matrix_ii(matrix):
minorred_matrix = [[] for i in range(matrix_metric(matrix)[0])]
m_sum = 0
for i in minorred_matrix:
m_sum += 1
#print(m_sum)
for i in range(len(matrix)):
for b in range(len(matrix[i])):
#print(i,b)
minorred_matrix[i].append(det_matrix_ii(minor_matrix_i(matrix,i,b))algebraic_add(matrix)[i][b])


return minorred_matrix




def det_matrix(matrix):

main_new= 1
rev_new= 1
mat_main = matrix
mat_rev = matrix[::-1]

for i in range(len(mat_main)):
main_new = mat_main[i][i]
rev_new = mat_rev[i][i]

det = (main_new - rev_new)
return det


def det_matrix_ii(matrix):
m_sum = 0
for i in matrix:
m_sum += 1
#print(‘сумма элементов’,m_sum)
determ_num = 0
for n in range(len(matrix)):

if m_sum == 2:
determ_num += matrix[0][n] * (minor_matrix_i(matrix,0,n))[0][0] * algebraic_add(matrix)[0][n]
# print(matrix[0][n],'‘,(minor_matrix_i(matrix,0,n))[0][0],’',algebraic_add(matrix)[0][n])
“”“else:
minor_sum = 0
for i in minor_matrix_i(matrix,0,n):
minor_sum += 1
print(‘сумма минорв’,minor_sum)
while minor_sum != 2:
det_matrix_ii(minor_matrix_i(matrix, 0, n))”“”
if m_sum == 3:
determ_num += matrix[0][n] * det_matrix_ii(minor_matrix_i(matrix, 0, n)) * algebraic_add(matrix)[0][n]
# print(matrix[0][n], '’, det_matrix_ii(minor_matrix_i(matrix, 0, n)), ‘*’, algebraic_add(matrix)[0][n])
return determ_num




def algebraic_add(matrix):
algebraic_added= [[ ((-1)**(2+m+n)) for n in range (matrix_metric(matrix)[0])] for m in range (matrix_metric(matrix)[0]) ]
return algebraic_added      def create_matrix(matrix,m,n):
    matrix = []
    for i in range(m):
        matrix.append([])

    for i in matrix:
        for h in range(n):
            i.append(0)
    return matrix


def create_and_print_matrix():
    # Get the matrix dimensions from the entry_fields list
    m = len(entry_fields)
    n = len(entry_fields[0])

    matrix = create_matrix([], m, n)

    # Get the values from the entry_fields and update the matrix
    for i in range(m):
        for j in range(n):
            entry_value = entry_fields[i][j].get()
            try:
                matrix[i][j] = int(entry_value)
            except ValueError:
                # Handle non-integer values entered in the entry fields
                print(f"Invalid value entered at row {i+1}, column {j+1}")

    # Display the matrix
    return matrix


def add_or_remove_row():
    metric_sum = 0

    for i in entry_fields:
        metric_sum += 1
    if metric_sum ==2:
        print(metric_sum)
        entry_fields.append([])
        for j in range(len(entry_fields[0])):
            entry = Entry(root, width=5)
            entry.grid(row=len(entry_fields), column=j+1)
            entry_fields[len(entry_fields)-1].append(entry)
    if metric_sum == 3:
        if len(entry_fields) > 2:
            for entry in entry_fields[-1]:
                entry.destroy()
            entry_fields.pop()


def add_or_remove_column():

    metric_sum = 0
    metric_sum += len(entry_fields[0])

    if metric_sum == 2:
        for row in entry_fields:
            row.append(Entry(root, width=5))
            row[-1].grid(row=entry_fields.index(row)+1, column=len(row))

    if metric_sum > 2:
        for row in entry_fields:
            if len(row) > 2:
                entry = row[-1]
                entry.destroy()
                row.pop()

root = Tk()
root.title("Матрица")
root.geometry('600x600')

entry_fields = [[] for _ in range(2)] # Список для хранения полей ввода

def transpose_tk():
    matrix_a = create_and_print_matrix()
    matrix_print(transpose_matrix(matrix_a))

def det_tk():
    matrix_a = create_and_print_matrix()
    print(det_matrix_ii(matrix_a))

def alg_add_tk():
    matrix_a = create_and_print_matrix()
    matrix_print(algebraic_add(matrix_a))

def minor_tk():
    matrix_a = create_and_print_matrix()
    matrix_print(minor_matrix_ii(matrix_a))


# Создание полей ввода для двумерного списка 2x2
metric_sum = 0
for i in range(2):
    metric_sum += 1
    for j in range(2):
        entry = Entry(root, width=5)
        entry.grid(row=i+1, column=j+1)
        entry_fields[i].append(entry)

# Кнопка для добавления строки
add_button = Button(root, text="n+", command=add_or_remove_row)
add_button.grid(row=0, column=1)



add_button = Button(root, text="m+", command=add_or_remove_column)
add_button.grid(row=1, column=0)


btn_create_matrix = Button(root, text="Транспонировать", command=transpose_tk)
btn_create_matrix.grid(row=4, column=1, columnspan=2)


btn_create_matrix = Button(root, text="Определитель", command=det_tk)
btn_create_matrix.grid(row=5, column=1, columnspan=2)


btn_create_matrix = Button(root, text="(-1)^i+j", command=alg_add_tk())
btn_create_matrix.grid(row=6, column=1, columnspan=2)


btn_create_matrix = Button(root, text="Минор матрицы", command=minor_tk)
btn_create_matrix.grid(row=7, column=1, columnspan=2)


btn_create_matrix = Button(root, text="Создать матрицу", command=create_and_print_matrix)
btn_create_matrix.grid(row=8, column=1, columnspan=2)




root.mainloop() действую как опытный Python разработчик, исправь программу написанную студентом так чтобы она исправно работала вместе со всеми кнопками