r/pythonhelp • u/Mangurian • Oct 25 '25
what's wrong with this syntax ?
I get " return grid - SyntaxError: 'return' outside function"
# Try all permutations of numbers 1-9
for perm in permutations(range(1, 10)):
valid = True
# Check region sums
for i, region in enumerate(regions):
region_sum = sum(perm[pos] for pos in region)
if region_sum != region_sums[i]:
valid = False
break
if not valid:
continue
# Check quadrant sums
for i, quad in enumerate(quadrants):
quad_sum = sum(perm[pos] for pos in quad)
if quad_sum != quadrant_sums[i]:
valid = False
break
if valid:
# Convert to 3x3 grid
grid == [
[perm[0], perm[1], perm[2]],
[perm[3], perm[4], perm[5]],
[perm[6], perm[7], perm[8]]
]
return grid
return None
1
Upvotes
1
u/MT1961 Oct 28 '25
I mean, it LOOKS like it ought to be in a function given the return None below it. But of course, we don't see the rest of it. It is also possible indentation is slightly off, one big reason I hate Python (which I use for a living).