-
Notifications
You must be signed in to change notification settings - Fork 1
/
matrices-by-user-input.py
55 lines (32 loc) · 1.28 KB
/
matrices-by-user-input.py
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
numberOfRows = int(input('Enter the number of Rows: '))
numberOfColumns = int(input('\nEnter the number of Columns: '))
matrices = []
for i in range(numberOfRows):
rows = []
for j in range(numberOfColumns):
elementOfMatrices = int(input(f'\nEnter the element at position ({i},{j}): '))
rows.append(elementOfMatrices)
matrices.append(rows)
for i in range(len(matrices)):
sumOfMatrices = []
for j in range(len(matrices[i])):
sumOfMatric = i + j
sumOfMatrices.append(sumOfMatric)
print()
print('-' * 54)
print(f'MatricIndex{i}', '\t', f'MatricIndex{j}', '\t', 'Sum of Matric Indexes')
print(' ', i, '\t ', j, '\t ', sumOfMatrices[j])
# Step 4: Construct the output string manually
# output_str = "["
# for i in range(len(matrices)):
# output_str += "["
# for j in range(len(matrices[i])):
# output_str += str(matrices[i][j])
# if j < len(matrices[i]) - 1:
# output_str += ", "
# output_str += "]"
# if i < len(matrices) - 1:
# output_str += ", "
# output_str += "]"
# Step 5: Print the constructed output string
# print(output_str)