def initialize_board():
board1 = ['*', '*', '*']
board2 = ['*', '*', '*']
board3 = ['*', '*', '*']
print(board1)
print(board2)
print(board3)
return board1
return board2
return board3
So I initialized my board for tic-tac-toe in this first function
And then I have this function:
import random
def input_choice():
initialize_board()
player_1 = input('What is your name?')
player_2 = input('What is your name?')
#See who goes first
player_1_choice = input('Choose heads or tales')
player_2_choice = input('Choose head or tales')
if random.choice(['heads', 'tales']) == player_1_choice:
print(f'{player_1} goes first!')
else:
print(f'{player_2} goes first1')
placements = {1 : board1[0], 2 : board1[1], 3 : board1[2], 4 : board2[0], 5 : board2[1], 6 : board2[2], 7 : board3[0], 8 : board3[1], 9: board3[2]}
print(board1)
However I get an error saying that board1 is not defined when its been defined in the first function.
NameError Traceback (most recent call last)
<ipython-input-30-dd18b3b6beab> in <module>
----> 1 input_choice()
<ipython-input-29-1ebcf8044e68> in input_choice()
19 print(f'{player_2} goes first1')
20
---> 21 placements = {1 : board1[0], 2 : board1[1], 3 : board1[2], 4 : board2[0], 5 : board2[1], 6 : board2[2], 7 : board3[0], 8 : board3[1], 9: board3[2]}
22
23 print(board1)
NameError: name 'board1' is not defined