Python数独难题9 x 9检查器 为True时: 尝试: 文件=输入(“输入文件名:”) fi=打开(文件“r”) infle=fi.read() grid=[infle.split()中的列表(i)for i]#将数独拼图放入一个列表,以检查总数是否有效 检查=长度(网格) print(“此拼图中的总数为:”,检查)#计算数独拼图中的数字量 打破 除FileNotFoundError外: 打印(“输入的文件不存在”) def检查(填充): 计数=0 对于范围(0,9)内的j: 对于范围(0,9)内的n: 如果infle[j].count(infle[j][n])
您从未在该代码中显式调用函数Python数独难题9 x 9检查器 为True时: 尝试: 文件=输入(“输入文件名:”) fi=打开(文件“r”) infle=fi.read() grid=[infle.split()中的列表(i)for i]#将数独拼图放入一个列表,以检查总数是否有效 检查=长度(网格) print(“此拼图中的总数为:”,检查)#计算数独拼图中的数字量 打破 除FileNotFoundError外: 打印(“输入的文件不存在”) def检查(填充): 计数=0 对于范围(0,9)内的j: 对于范围(0,9)内的n: 如果infle[j].count(infle[j][n]),python,Python,您从未在该代码中显式调用函数check。我怀疑它还不止这些。填充可能应该是网格。还有其他一些事情。 while True: try: file = input("Enter a filename: ") fi = open(file, "r") infile = fi.read() grid = [list (i) for i in infile.split()] #Puts the sudoku puzzle into
check
。我怀疑它还不止这些。填充可能应该是网格。还有其他一些事情。
while True:
try:
file = input("Enter a filename: ")
fi = open(file, "r")
infile = fi.read()
grid = [list (i) for i in infile.split()] #Puts the sudoku puzzle into a list in order to check that the total number is valid
check = len(grid)
print("The total number in this puzzle is:",check) #Counts the amount of numbers in the sudoku puzzle
break
except FileNotFoundError:
print ("The inputted file does not exist")
def check(infile):
count = 0
for j in range (0,9):
for n in range(0,9):
if infile[j].count(infile[j][n]) <= 1:
count = count + 0
else:
count = count + 1