-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path72.py
More file actions
94 lines (66 loc) · 1.4 KB
/
72.py
File metadata and controls
94 lines (66 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import random
N = 4
M = 6
def get_row(column):
col = []
for i in range(0, column):
col.append(random.randint(0, 9))
return col
def get_matrix(row, column):
matrix = []
for i in range(0, row):
matrix.append(get_row(column))
return matrix
def print_matrix(matrix):
i = 0
while i < len(matrix):
j = 0
row = matrix[i]
while j < len(row):
column = row[j]
print(column, end=' ')
j += 1
print()
i += 1
def get_average(row):
sum = 0
for element in row:
sum += element
return sum/len(row)
def get_column(matrix, index):
column = []
i = 0
while i < len(matrix):
column.append(matrix[i][index])
i += 1
return column
A = get_matrix(N, M)
print("Исходная матрица:")
print_matrix(A)
sum = 0
i = 0
while i < len(A):
j = 0
while j < len(A[i]):
sum += A[i][j]
j += 1
i += 1
i = 0
new_row = []
while i < len(A):
j = 0
while j < len(A[i]):
if len(new_row) <= j:
new_row.append(A[i][j])
else:
new_row[j] += A[i][j]
j += 1
i += 1
i = 0
while i < len(new_row):
new_row[i] = new_row[i]/sum
i += 1
A.append(new_row)
print("Сумма всех элементов:", sum)
print("Модифицированная матрица:")
print_matrix(A)