1 | initial version |
This works for me :
import itertools
min_params=[] ## Do,'t forget to intitialize !
for (a,b) in itertools.product([u for u in (-2..2)], repeat=2):
M = Matrix(ZZ, [[0,a],[b,0]])
if M.determinant()==2: ## Mind the indentation : this is part of the loop...
min_params.append((a,b)) ## No need for an else clause
print 'Sets of parameters with this determinant:', min_params
Sets of parameters with this determinant: [(-2, 1), (-1, 2), (1, -2), (2, -1)]
You seem to struggle with the basics of the (admittedly peculiar) Python syntax, where (among others) whitespace is syntaxic...
I'd suggest to peruse a good Python tutorial ; keep in mind that Sage is currently Python2-based, but should soon (?) be Python3-based (and yes, there are a lot of devils in the seemingly small details...).
HTH,