11th Oct 2022, 1:30 PM
Jothika
Jothika - avatar
4 Answers
+ 3
#read the comments to know about errors ; hope it helps to correct code by yourself.. def transpose(m1): m2=m1 # here missing outer loop for j for i in range(0,len(m1)): m2[i][j]=m1[i][j] # think about logic again, you just return same array.. return m2 row=int(input("Enter the number of rows")) column=int(input("Enter the number of columns") # ) missing M1=[] for i in range(0,row): r=list(input("Enter the row to be added") # ) mising M1.append(r) M2=transpose(M) #M1, not M for j in range(0,row): for i in range of (0,column): # what is range of ? just use range print(M2[j][i],end=" ") print()
11th Oct 2022, 1:49 PM
Jayakrishna 🇼🇳
+ 2
def transpose(m1,c,r): m2=[] for i in range(0,c): a=[] for j in range(0,r): a.append(j) m2.append(a) for j in range(0,c): for i in range(0,r): m2[i][j]=m1[j][i] return m2
11th Oct 2022, 5:04 PM
Oma Falk
Oma Falk - avatar
11th Oct 2022, 2:03 PM
Jothika
Jothika - avatar
+ 1
You are actually declaring 1d list but trying to access 2d list. In addition to @Oma Falk, While taking input also, first add the current row to a empty list. then add total list of row values to another list, that makes a 2d list.. hope it helps.
11th Oct 2022, 6:07 PM
Jayakrishna 🇼🇳