Answer to Question #262008 in Python for prime

Question #262008
For this program, the output should not have any brackets

M, N = input().split()
M, N = int(M), int(N)
matrix = []
for _ in range(M):
 row = [int(x) for x in input().split()]
 matrix.append(row)
K = int(input())
values = []
k = 0
l = 0
while (((N - k) > 0) and ((M - l) > 0)) and ((N - k)*(M-l)) > K:
 for i in range(k,N):
 values.append(matrix[k][i])
 for j in range(l+1,M):
 values.append(matrix[j][N-1])
 for i in range(N-2,k-1,-1):
 values.append(matrix[M-1][i])
 for j in range(M-2,l,-1):
 values.append(matrix[j][k])
 values = values[-K:] + values[:-K]
 c = 0
 for i in range(k,N):
 matrix[k][i] = values[c]
 c += 1
 for j in range(l+1,M):
 matrix[j][N-1] = values[c]
 c += 1
 for i in range(N-2,k-1,-1):
 matrix[M-1][i] = values[c]
 c += 1
 for j in range(M-2,l,-1):
 matrix[j][k] = values[c]
 c += 1 
 values = []
 k += 1
 l += 1
 M -= 1
 N -= 1
for i in matrix:
 print(i)
1
Expert's answer
2021-11-06T18:56:45-0400


SOLUTION FOR THE ABOVE QUESTION


SOLUTION CODE


M, N = input("Enter the number of rows and columns of your matrix separated by space:").split()
M, N = int(M), int(N)
matrix = []
rows_count = 1;
for _ in range(M):
 print("Enter the values("+str(N)+") values for row "+str(rows_count)+": ")
 rows_count = rows_count+1;
 #split the values of the row matrix
 row = [int(x) for x in input().split()]
 #add the row to your matrix
 matrix.append(row)
K = int(input("Enter value of k:"))
values = []
k = 0
l = 0
while (((N - k) > 0) and ((M - l) > 0)) and ((N - k)*(M-l)) > K:
 for i in range(k,N):
    values.append(matrix[k][i])
 for j in range(l+1,M):
    values.append(matrix[j][N-1])
 for i in range(N-2,k-1,-1):
    values.append(matrix[M-1][i])
 for j in range(M-2,l,-1):
    values.append(matrix[j][k])
    values = values[-K:] + values[:-K]
 c = 0
 for i in range(k,N):
    matrix[k][i] = values[c]
 c += 1
 for j in range(l+1,M):
    matrix[j][N-1] = values[c]
 c += 1
 for i in range(N-2,k-1,-1):
    matrix[M-1][i] = values[c]
 c += 1
 for j in range(M-2,l,-1):
    matrix[j][k] = values[c]
 c += 1
 values = []
 k += 1
 l += 1
 M -= 1
 N -= 1
#Now let us print our matrix without having the brackets
#make the output not have brackes
print("Matrix output without brackets")
for i in matrix:
    for j in range(0,N+1):
        if j == N:
            print(i[j])
        else:
            print(i[j], end="  ")
    


SAMPLE PROGRAM OUTPUT





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS