|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import math
sudokuGrid = [
[0,0,0,1],
[0,2,0,0],
[0,0,4,0],
[3,0,0,0]
]
size = len(sudokuGrid)
print("Sudoku grid size is ", size, " by ", size)
for row in range(size):
print (sudokuGrid[row])
area = int(math.sqrt(size))
print ("Size of each area is: ", area, " by ",area)
for target in range(1,size+1):
row = 0
while (row < size):
col = 0
while (col < size):
print("\nChecking the following area for target value: ",target)
print("start row: ", row)
print("end row: ", row + area - 1)
print("start col: ", col)
print("end col: ", col + area - 1)
print()
#print ("Looking for ", target)
for r in range(row, row + area):
for c in range(col, col + area):
#print ("Checking - Row: ", r, " Column: ", c,end="")
if (sudokuGrid[r][c] == target):
print ("Target is already in area")
#else:
#print (" - Not here")
row += area
col += area
这个代码里面为什么总说最后一行col += area 不能缩进呢,但是如果我不缩进,跟row += area是一排的话就一直运行,求助!
所以你的 col += area 和 row += area 是想在 while 迴圈里面,还是外面?(能不能缩排是看你想把 col 或 row 放进 while 迴圈,还是放外面) while True: # while A
while True: # while B
row += area # 在 while A 和 while B 里面
col += area # 在 while A 里面,在 while B 外面
|
|