0

python, help

import random def matrix(rows): mat = [[random.randint(0,10) for j in range(rows)] for i in range(rows)] for i in range(rows): print (mat[i]) matrix(3) Help me to change the code above, i need to have print result not like list but like this: 1 1 1 2 2 1 3 3 1

17th Nov 2018, 11:36 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
2 Answers
+ 1
Just write: print(*mat[i])
17th Nov 2018, 11:48 PM
HonFu
HonFu - avatar
0
Just a little modification: import random def matrix(rows): mat = [[random.randint(0,10) for j in range(rows)] for i in range(rows)] for i in mat: for j in i: print (j, end=" ") print() matrix(3)
18th Nov 2018, 2:25 AM
Шащи Ранжан
Шащи Ранжан - avatar