I am learning to use Python from Udemy Zero to Hero course and am really struggling with the milestone#1 project. I am creating a very simple tic tac toe game and I have gotten only has far as creating 1) a board 2) assigning each player 3) putting first player on the board. I will be honest i am not sure if the code I did is a good way to do any of this, but I am a bit confused 1.) if I should be using parameters(still a bit confused by when and when not to use them- maybe it will help the code be more flexible?) as my code works without it, and 2) what I should do next- I know I need to create a function to see if its been won, tied or lost but not sure how to bring that function back to the ones I have made-should make the return of that function be a boolean and then try to use it elsewhere? Any help would be appreciated to help me progress forward as I don't want to look at the solutions until I can at least somewhat create something myself.
FYI i am using pycharm if that matters
Thanks!
board = [' '] * 9
player_1 = None
player_2 = None
current_player = None
position = None
acceptable_range = [0,1,2,3,4,5,6,7,8]
players = None
def game_board(board):
print('\n' * 100)
print(board[0] + "|" + board[1] + "|" + board[2])
print(" --- ")
print(board[3] + "|" + board[4] + "|" + board[5])
print(" --- ")
print(board[6] + "|" + board[7] + "|" + board[8])
def assign_players():
#only allow 'X' or 'O'
acceptable_values= ['X','O']
# asks player 1 what letter he wants
global player_1
global player_2
global current_player
global players
player_1 = input('Player 1 would you like to be X or O: ').upper()
while player_1 not in acceptable_values:
player_1 = input('Please choose only X or O: ').upper()
if player_1 == 'X':
player_2 = 'O'
else:
player_2 = 'X'
players = [player_1, player_2]
def position_placement():
#request input from player_1 and make sure its int and within range
global acceptable_range
global current_player
global position
global players
current_player = players[0]
while position == None:
position = int(input('Please choose a number between 0-8: '))
while position not in acceptable_range:
position = int(input('Incorrect value! Sorry please try again: '))
# take position and assign to player_1 value
board[position] = current_player
# pop off position from acceptable_range so it can't be chosen again
acceptable_range.pop(position)
#show the new board
return (game_board(board))