Answer to Question #196486 in Python for Narendra

Question #196486
m, n = input('Enter the values of M and N separated by a space: ').split()
m = int(m)
n = int(n)
matrix_str = input('Enter all matrix values separated by a space: ').split()

matrix = [matrix_str[n*i:n*(i+1)] for i in range(m)]

for i in range(n):
    for j in range(i+1):
        try:
            print(matrix[j][i-j],end=' ')
        except:
            break
    print('')

for i in range(1,m):
    for j in range(i+1):
        try:
            print(matrix[i+j][-1-j],end=' ')
        except:
            break
    print('')  



In this answer why did we use for i in range(m) while getting matrix

can you please explain to me why we used it like that and can we use it like that


1
Expert's answer
2021-05-21T23:48:18-0400

for i in range(m) - It takes element from matrix_str row wise that's why we use that.


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