hw 3.8 Submission did not terminate

I have a problem that I don't quite grasp. I know that there is a bug with the homework checker. However all the typical solutions, such as adding blank lines, don't seem to solve the problem. Could someone please give me some advise?

This is my code:

def check_sudoku(list):

    for i in range(len(list)):
        row = []
        column = []
        for j in range(len(list)):
            if list[i][j] in row or list[i][j]>len(list): 
                return False
            elif list[j][i] in row or list[j][i]>len(list): 
                return False
            else:
                row.append(list[i][j])
                column.append(list[j][i])
    return True

print check_sudoku(correct)

asked 18 Mar '12, 16:59

juan_fasching's gravatar image

juan_fasching
1
accept rate: 0%

edited 18 Mar '12, 17:09

Anton%20Golov's gravatar image

Anton Golov ♦
13.3k2174174


2 Answers:

You never use column, while you probably should be for the column checks. I see no reason for your code to loop forever, but this will cause it to sometimes return incorrect results.

link

answered 18 Mar '12, 17:23

Anton%20Golov's gravatar image

Anton Golov ♦
13.3k2174174

I got the same message. Ran it several times in IDLE, and terminated just fine.

def check_sudoku(l):
n = len(l)
if n < 1: return False
for k in l:
    if len(k) != n: return False
for i in range(n):
    if l[i][i] in l[i][:i]+l[i][i+1:]: return False
    vert.append([])
    for j in range(n):
        vert[i].append(l[i][j])
    if vert[i][i] in vert[i][:i]+vert[i][i+1:]: return False
return True
link

answered 18 Mar '12, 17:46

Andy%20Nees-3's gravatar image

Andy Nees-3
446

edited 18 Mar '12, 17:46

Your answer
Question text:

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15,234
×118
×15

Asked: 18 Mar '12, 16:59

Seen: 115 times

Last updated: 18 Mar '12, 17:46