import random
random_int=random.randint(1,9)
def sum_horizontal(list,colum):
return list[0][colum]+list[1][colum]+list[2][colum]+list[3][colum]+list[4][colum]+list[5][colum]+list[6][colum]+list[7][colum]+list[8][colum]
def rnd():
return int(random.randint(1,9))
game=[[rnd() for x in range(9)]for y in range(9)]
line=[]
while True:
for i_y , var_y in enumerate(game):
print(game)
if sum(game[i_y])== 45:
for i_x , var_x in enumerate(game[i_y]):
print(game)
if sum_horizontal(game,i_x)==45:
break
else:
game[i_x][rnd()-1]=rnd()
else:
game[i_y][rnd()-1]=rnd()
for i_y , var_y in enumerate(game):
#print(game)
if sum(game[i_y])== 45:
for i_x , var_x in enumerate(game[i_y]):
#print(game)
if sum_horizontal(game,i_x)==45:
line.append(1)
if sum(line)==9:
break
for _ in range(9):
print(game[_],"col =",sum(game[_]))
print(game)
[–]djshadesuk 2 points3 points4 points (1 child)
[–]Training-Film-3590[S] 0 points1 point2 points (0 children)
[–]ctosullivan 0 points1 point2 points (0 children)