weixin_46843112 2020-04-06 03:17 采纳率: 0%

# TypeError: unsupported operand type(s) for //: 'NoneType' and 'int'

``````def row(i, sudoku):
# 返回一行
row_list = []
for q in range((i-1)*9, (i-1)*9+9):
row_list.append(sudoku[q])

return row_list

def col(j, sudoku):
# 返回一列
col_list = []
for w in range((j-1) % 9, 80, 9):
col_list.append(sudoku[w])

return col_list

def sub(i, j, sudoku):
# 返回一宫
sub_list = []
"""多个条件得到宫数，待优化"""
if i <= 3:
if j <= 3:
e = 1
r = 1
elif j <= 6:
e = 2
r = 4
else:
e = 3
r = 7
elif i <= 6:
if j <= 3:
e = 4
r = 28
elif j <= 6:
e = 5
r = 31
else:
e = 6
r = 34
else:
if j <= 3:
e = 7
r = 55
elif j <= 6:
e = 8
r = 58
else:
e = 9
r = 61

"""e为宫数，r为该宫的第一个数字，手动计算得到的"""

for t in range(r - 1, r + 2):
sub_list.append(sudoku[t])
for t in range(r + 8, r + 11):
sub_list.append(sudoku[t])
for t in range(r + 17, r + 20):
sub_list.append(sudoku[t])

return sub_list

def problem(sudoku):
# 找到空点
problem_list = []
for z in range(0, 80):
if sudoku[z] == 0:
problem_list.append(z)

return problem_list

def start_problem(sudoku):
"""第一个空点"""
problem_list = problem(sudoku)
x = problem_list[0]
return x

def next_problem(i, j, sudoku):
# 下一个空格
x = turn(i, j)
if sudoku[x] == 0:
for y in range(x, 80):
if sudoku[y] == 0:
return y + 1

def turn(i, j):
"""行列位置转列表位置"""
z = (i - 1) * 9 + j - 1
return z

def get_i(x):
"""列表位置得行数"""
i = 0
i = x // 9 + 1
return i

def get_j(x):
"""列表位置得列数"""
j = 0
j = x % 9 + 1
return j

def check(number, x, sudoku):
"""数独规则"""
i = get_i(x)
j = get_j(x)
row_list = row(i, sudoku)
col_list = col(j, sudoku)
sub_list = sub(i, j, sudoku)
if number not in row_list and number not in col_list and number not in sub_list:
return True
else:
return False

def available(i, j, sudoku):
"""一个位置的备选数字"""
available_list = []
row_list = row(i, sudoku)
col_list = col(j, sudoku)
sub_list = sub(i, j, sudoku)
for number in range(1, 10):
if number not in row_list and number not in col_list and number not in sub_list:
available_list.append(number)

return available_list

def try_fill(i, j, sudoku):
"""一格尝试"""
a = turn(i, j)

for value in available(i, j, sudoku):
if sudoku[a] == 0:
sudoku[a] = value
b = 0
b = next_problem(i, j, sudoku)
w = get_i(b)
e = get_j(b)
try_fill(w, e, sudoku)

def fill(sudoku):
"""填空"""
x = start_problem(sudoku)
i = get_i(x)
j = get_j(x)
try_fill(i, j, sudoku)

return sudoku

"""最终答案"""
fill(sudoku)
print(sudoku)
``````

Traceback (most recent call last):
File "C:/Users/yl/PycharmProjects/shudu/sudo.py", line 215, in
fill(sudoku2)
File "C:/Users/yl/PycharmProjects/shudu/sudo.py", line 171, in fill
try_fill(i, j, sudoku)
File "C:/Users/yl/PycharmProjects/shudu/sudo.py", line 160, in try_fill
w = get_i(b)
File "C:/Users/yl/PycharmProjects/shudu/sudo.py", line 114, in get_i
i = x // 9 + 1
TypeError: unsupported operand type(s) for //: 'NoneType' and 'int'

• 写回答

#### 悬赏问题

• ¥15 C语言，密切接触者追踪
• ¥20 关于计算机网络问题，请附带讲解
• ¥20 论文附带的代码如何运行？
• ¥30 自动识别图像目标并判断
• ¥30 BP神经网络遥感图像分类问题
• ¥20 新闻小程序6万人在线
• ¥15 Fluent轴流风扇模拟
• ¥15 基于GPS的自行车定位系统设计
• ¥15 idea中安装matplotlib模块完成，运行还是显示无安装
• ¥15 robotframework 运行报错