Need to import a txt file to Python and use it with this code (Convert input line to list, append it, and return value) -


i have been writing code hour , can't final step. need modify code below. i've tried , read, it's somewhere in first 3 lines (but whole code may need modified). need convert each input line list, append board list, , return sudoku board @ end.

the output @ end should enter file initial s board ==>; enter board3.txt (included @ end of post) , diagram made in code.

def read_board(fn):     board = []     line in open(fn,'r'):         # fixme  def print_board( board ):     r in range(0,9):         if r%3 == 0:             print '-'*25         print '|',         c in range(0,9):             print board[r][c],             if c==2 or c==5:                 print '|',             elif c==8:                 print '|'     print '-'*25  def ok_to_add(row,col,num,board):     return true  if __name__ == "__main__":     name = raw_input("enter file initial s board ==> ").strip()     board = read_board(name)     print_board(board) 

board3.txt:

1 . . . 2 . . 3 7 . 6 . . . 5 1 4 . . 5 . . . . . 2 9 . . . 9 . . 4 . . . . 4 1 . 3 7 . . . . 1 . . 4 . . . 4 3 . . . . . 1 . . 1 7 5 . . . 8 . 2 8 . . 4 . . . 6 

you need split each line. automatically divide line whitespace , make list you.

def read_board(fn):     open(fn, 'r') file:         return [line.split() line in file] 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -