+ 1

This is printing 1st row only and not slicing it to the given number of rows. Please help!

#define a function to print the matrix def matrix_print(matrix, x, y): #matrix_print(matrix, rows, columns) a = 0 for m in range(x): n=y print(matrix[a:n]) if n == y+1: a=y+1 n=y*2

5th May 2018, 11:38 AM
Siddharth Mishra
Siddharth Mishra - avatar
4 Respuestas
+ 1
cannot copy to code playground but at first glance it seems that you iterate only the colums in the first row. you do need two cycles nested.
5th May 2018, 1:20 PM
tamaslud
tamaslud - avatar
0
#define a function to print the matrix def matrix_print(matrix, x, y): #matrix_print(matrix, rows, columns) a = 0 for m in range(x): n=y print(matrix[a:n]) if n == y+1: a=y+1 n=y*2 def matrix_input(): #take matrix input #define the matrix matrix = [] #take the no. of rows in the matrix i = float(input("Please enter the number of rows in the matrix : ")) #check if the input is correct for rows if i%1 != 0: i = int(i) print("Wrong input! : Decimal converted to integer") i = int(i) j = float(input("Please enter the number of rows in the matrix : ")) #check if the input is correct for columns if j%1 != 0: j = int(i) print("Wrong input! : Decimal converted to integer") j = int(j) #take input using loop m = 0 n = 0 #define the loop for m in range(i): #this loop is for rows for n in range(j): #this loop is for columns str = "Enter the elemnt of row {x} column {y} : ".format(x=m+1,y=n+1) k = float(input(str)) matrix.append(k) matrix_print(matrix, i, j) matrix_input() This is the complete code
5th May 2018, 11:38 AM
Siddharth Mishra
Siddharth Mishra - avatar
0
Please help
5th May 2018, 11:39 AM
Siddharth Mishra
Siddharth Mishra - avatar
0
Good
18th May 2018, 9:45 PM
Suyahman
Suyahman - avatar