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
2 Réponses
+ 1
Just write:
print(*mat[i])
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)