forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput matrice,product any order!.py
69 lines (53 loc) · 1.4 KB
/
input matrice,product any order!.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# inputing 2 matrices:
# matrice 1:
rows = int(input("Enter the number of rows of the matrice 1"))
coloumns = int(input("Enter the coloumns of the matrice 1"))
matrice = []
rowan = []
for i in range(0, rows):
for j in range(0, coloumns):
element = int(input("enter the element"))
rowan.append(element)
print("one row completed")
matrice.append(rowan)
rowan = []
print("matrice 1 is \n")
for ch in matrice:
print(ch)
A = matrice
# matrice 2:
rows_ = coloumns
coloumns_ = int(input("Enter the coloumns of the matrice 2"))
rowan = []
matrix = []
for i in range(0, rows_):
for j in range(0, coloumns_):
element = int(input("enter the element"))
rowan.append(element)
print("one row completed")
matrix.append(rowan)
rowan = []
print("Matrice 2 is\n")
for ch in matrix:
print(ch)
B = matrix
# creating empty frame:
result = []
for i in range(0, rows):
for j in range(0, coloumns_):
rowan.append(0)
result.append(rowan)
rowan = []
print("\n")
print("The frame work of result")
for ch in result:
print(ch)
# Multiplication of the two matrices:
for i in range(len(A)):
for j in range(len(B[0])):
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]
print("\n")
print("The product of the 2 matrices is \n")
for i in result:
print(i)