I'm trying to print a matrix with user assigned variable for the length and width, but have used manual assignment for easier reading. Right now my output doesn't include any new lines, but that is what I'm attempting to do.
def matrix(rows,cols):
grid = [[0 for i in range(cols)] for i in range(rows)]
return grid
rows = 5
cols = 5
print(matrix(rows,cols))
Is it possible to insert a print("\n") statement into the for statement to properly print out the matrix. Currently the output is as follows:
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
Desired output:
[[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]]