Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #predefined var
- first = None
- second = None
- result = None
- col_ = 0
- row = 0
- #class
- class Matrix:
- def __init__(self, row, col):
- self.row=row
- self.col=col
- self.matrix = [[[]for i in range(col)] for i in range(row)]
- def create(self):
- for i in range(0, self.row):
- for j in range(0, self.col):
- self.matrix[i][j] = input("Input row %d & col %d : " %(i+1, j+1))
- def view(self):
- for i in range(0, self.row):
- for j in range(0, self.col):
- print "%d" %(self.matrix[i][j]),
- print ""
- def firstMatrix():
- print "First Matrix"
- row_ = input("Row ? ")
- global col_
- col_ = input("Col ? ")
- global first
- first = Matrix(row_,col_)
- first.create()
- def secondMatrix():
- print "Second Matrix"
- global row
- while row != col_:
- row = input("Row ? ")
- col = input("Col ? ")
- global second
- second = Matrix(row,col)
- second.create()
- def doMultiply():
- global result
- result = Matrix(first.row, second.col)
- for i in range(0, result.row):
- for j in range(0, result.col):
- result.matrix[i][j] = 0
- for i in range(0,first.row):
- for j in range(0,second.col):
- for k in range(0,second.row):
- result.matrix[i][j] += first.matrix[i][k] * second.matrix[k][j]
- print "\n"*25
- firstMatrix()
- print "_"*80,
- secondMatrix()
- doMultiply()
- print "_"*80
- result.view()
Add Comment
Please, Sign In to add comment