Python Game | TypeError: argument of type 'NoneType' is not iterable -


so i'm working through python book , asked create tic-tac-toe game , understand code do, relatively. come time run program , given weird error

typeerror: argument of type 'nonetype' not iterable

with full error being:

traceback (most recent call last):    file "tac tac toe game revised.py", line 182, in <module>      main()    file "tac tac toe game revised.py", line 173, in main      move = human_move(board, human)    file "tac tac toe game revised.py", line 100, in human_move      while move not in legal: typeerror: argument of type 'nonetype' not iterable 

here code refers in line 173

def main():     display_instruction()     computer,human = pieces()     turn = x     board = new_board()     display_board(board)     while not winner(board):        if turn == human:            move = human_move(board, human)            board[move] == human        else:            move = computer_move(board,computer,human)            board[move] == computer        display_board(board)        congrats_winner(the_winner,computer, human) 

the error occurs in following function:

def human_move(board,human): '''get human move''' legal = legal_moves(board) move = none while move not in legal:     move = ask_number('where move? (0-8): ',0, num_squares)     if move not in legal:         print ('\nthat square occupied, foolish human. choose another.\n') print('fine...') return move 

i've tried changing move = none move = ' ' made no difference. ideas?

as requested here's function legal_moves

def legal_moves(board): '''creates legal list of moves'''    moves = []    square in range(num_squares):       if board[square] == empty:           moves.append(square) 

you need return moves list:

def legal_moves(board):     '''creates legal list of moves'''     moves = []     square in range(num_squares):         if board[square] == empty:             moves.append(square)     return moves 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -