Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # #Question 5
- # def matrix(mat,ln,col):
- # """Create A Matrix with lists of rows as elements"""
- # mat = list(mat)
- # matt = []
- # for i in range (ln):
- # matt.append(mat[i*col:i*col+col])
- #
- #
- # def add_line(line):
- # """Add Line to matrix"""
- # line = list(line)
- # nonlocal matt
- # matt.append(line)
- # nonlocal ln
- # ln=ln+1
- #
- # def add_column(column):
- # """Add add_column to matrix"""
- # for i in range(len(matt)):
- # matt[i].append(column[i])
- #
- # nonlocal col
- # col = col+1
- #
- # def shift_up():
- # """Shifts matrix up"""
- # nonlocal matt
- # temp=(matt.pop(0))
- # matt.append(temp)
- #
- # def shift_down():
- # """Shifts matrix down"""
- # nonlocal matt
- # temp=(matt.pop(len(matt)-1))
- # matt.insert(0,temp)
- #
- # def shift_right():
- # """Shifts matrix right"""
- # nonlocal matt
- # for i in matt:
- # temp = i.pop(col-1)
- # i.insert(0,temp)
- #
- # def shift_left():
- # """Shifts matrix left"""
- # nonlocal matt
- # for i in matt:
- # temp = i.pop(0)
- # i.append(temp)
- #
- # def transpose():
- # """transpose matrix"""
- # nonlocal matt
- # nonlocal col
- # nonlocal ln
- # res =[]
- # for i in range (col):
- # res.append(list(map(lambda f:f[i],matt)))
- #
- #
- # col,ln = ln,col
- # matt = res
- #
- # def line():
- # """return amount of lines in matrix"""
- # return ln
- # def column():
- # """return amount of column in matrix"""
- # return col
- #
- # def print_matt():
- # """returns dictionary with print method that have a copy of mat"""
- # res =[]
- # for x in matt:
- # res.append(x.copy())
- #
- # def print_one():
- # """returns dict that has a line from mat"""
- # nonlocal res
- # res_o = res.pop(0)
- # def print_two():
- # """returns a single element from row and delete it"""
- # nonlocal res_o
- # return res_o.pop(0)
- #
- #
- # return {'print':print_two}
- #
- # return {'print':print_one}
- #
- #
- # return {'print':print_matt,'line':line,'column':column,'add_line':add_line,'add_column':add_column,'shift_up':shift_up,'shift_down':shift_down,'shift_right':shift_right,'shift_left':shift_left,'transpose':transpose}
- #
- #
- #
- # m1 = matrix ((1,2,3,4,5,6,7,8),2,4)
- # m1['add_line']((1,3,5,7))
- # m1['add_column']((2,4,6))
- #
- # matrix=m1['print']()
- # for _ in range(m1['line']()):
- # line=matrix['print']()
- # for _ in range(m1['column']()):
- # print(line['print'](),end=' ')
- # print()
- #
- # print('---------')
- #
- #
- # m1['shift_up']()
- # m1['shift_right']()
- # m1['transpose']()
- #
- # matrix=m1['print']()
- # for _ in range(m1['line']()):
- # line=matrix['print']()
- # for _ in range(m1['column']()):
- # print(line['print'](),end=' ')
- # print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement