-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_x_n_matrix
39 lines (33 loc) · 877 Bytes
/
m_x_n_matrix
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
#set matrix size
#create matrix, then print it. Return m and n
def set_matrix_size():
m = int(input("Set m: "))
n = int(input("Set n: "))
print("m=",m,"n=",n)
matrix_nm(m,n)
return m,n
#t is matrix with entries nxm and index number
t = {}
def matrix_nm(m,n):
for i in range(1,n+1):
for j in range(1,m+1):
t[len(t)+1] = [i,j,len(t)+1]
#prints a line of a matrix
def print_line(m,n,x):
for i in range(1,m+1):
print('%-2s' % str(t[i+(x-1)*m][2]), end = " ")
#puts together lines of matrix and displays it
def print_matrix(m,n):
for i in range(1,n+1):
print_line(m,n,i)
print("")
def main():
m,n = set_matrix_size()
print("")
print(m, "x",n,"- Matrix: ")
print_matrix(m,n)
print("")
print("'t'-Matrix:")
print(t)
if __name__ == '__main__':
main()