I wrote this program in Python 3.I would like to know if there is some more functionality that could be added/removed/is missing.Any comments would be helpful!
#Steps from user :
"""
Enter Input
P1 and P2
Each time for input will be preceded by a printed board.
The game will continue until an input matches a win combination.
"""
win_combinations = [
[1,2,3],
[4,5,6],
[7,8,9],
[1,4,7],
[2,5,8],
[3,6,9],
[1,5,9],
[3,5,7]]
tot_list = [1,2,3,4,5,6,7,8,9]
def board():
print ("{}|{}|{}".format(tot_list[0],tot_list[1],tot_list[2]))
print ("{}|{}|{}".format(tot_list[3],tot_list[4],tot_list[5]))
print ("{}|{}|{}".format(tot_list[6],tot_list[7],tot_list[8]))
p1 = 0
p2 = 0
def player_input():
global p1
global p2
while True:
try:
print("\n\n")
board()
print("\n")
p1 = int(input("P1(X): Enter your Input:"))
print("\n")
p2 = int(input("P2(O): Enter your Input:"))
if 0 < p1 < 10 and 0 < p2 < 10 :
assign_values(p1,p2)
break
print("Re-enter valid input")
except:
print("Invalid input")
continue
def assign_values(player1,player2):
if type(tot_list[player1-1]) == str() or type(tot_list[player2-1]) == str():
print("Re-enter valid input")
player_input()
if player1 in tot_list:
tot_list[player1-1] = "X"
if player2 in tot_list:
tot_list[player2-1] = "O"
p1_win = False
p2_win = False
tie = False
def default_values():
global tot_list
global p1
global p2
global p1_win
global p2_win
global tie
tot_list = [1,2,3,4,5,6,7,8,9]
p1 = 0
p2 = 0
p1_win = False
p2_win = False
tie = False
def play():
global p1_win
global p2_win
global tie
global tot_list
while True:
player_input()
for i in win_combinations:
if tot_list[i[0]-1] == "X" and tot_list[i[1]-1] == "X" and tot_list[i[2]-1] == "X":
p1_win = True
break
elif tot_list[i[0]-1] == "O" and tot_list[i[1]-1] == "O" and tot_list[i[2]-1] == "O":
p2_win = True
break
if all(isinstance(i,str) for i in tot_list) == True:
tie == False
if p1_win==True:
print("P1 has won!")
break
elif p2_win==True:
print("P2 has won!")
break
elif tie == True:
print("Its a tie!")
break
play_again = input("Play Again?(y/n)")
if play_again == "y":
default_values()
play()
else:
print("Ciao")
if __name__ == '__main__':
play()