|
发表于 2022-8-28 11:45:16
|
显示全部楼层
- import random
- d , n = [] , 0
- while n < 9:
- x = random . randint(1 , 9)
- if not x in d:
- d += [x]
- n += 1
- x = list(zip(*[iter(d)] * 3))
- print(x)
- for i in range(len(x)):
- for j in range(len(x[i])):
- if x[i][j] == 1:
- print('x[%d][%d] = 1' % (i , j))
复制代码
运行实况:
- D:\[00.Exerciese.2022]\Python>python x.py
- [(1, 7, 5), (6, 4, 2), (3, 8, 9)]
- x[0][0] = 1
- D:\[00.Exerciese.2022]\Python>python x.py
- [(6, 8, 4), (7, 1, 5), (3, 2, 9)]
- x[1][1] = 1
- D:\[00.Exerciese.2022]\Python>python x.py
- [(3, 9, 6), (5, 8, 7), (4, 1, 2)]
- x[2][1] = 1
- D:\[00.Exerciese.2022]\Python>python x.py
- [(9, 8, 5), (2, 7, 6), (4, 3, 1)]
- x[2][2] = 1
- D:\[00.Exerciese.2022]\Python>
复制代码 |
|