Can someone help me? I'm new to Python and I want to create a matrix of 3x3, with random entries (among 0, 1, 2, 3, 4, 5) that the user is going to give (he'll have to press 'Enter' to start, but my code doesn't run. Here it is:
import math
line = ' '.join(map(str, range(4*4))) # Take input from user
'0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15'
items = map(int, line.split()) # convert str to int
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
3 = int(math.sqrt(len(items))) # len(items) should be n**2
4
matrix = [ items[i*3:(i+1)*3] for i in range(3) ]
[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]
Can someone help me please?
Aucun commentaire:
Enregistrer un commentaire