I know most basic python syntax other than OOP stuff.
I tried building this tic tac toe game but the code does not work.
I think I messed up the while
loop where I string together all the functions.
Could you tell me what is wrong?
I am very new to programming. Any help is deeply appreciated.
def tic_tac_toe():
Numbers = [1,2,3,4,5,6,7,8,9]
Win = [(1,2,3),(4,5,6),(7,8,9),(1,4,7),(2,5,8),(3,6,9),(1,5,9),(3,5,7)]
def draw():
print(Numbers[0],Numbers[1],Numbers[2])
print(Numbers[3],Numbers[4],Numbers[5])
print(Numbers[6],Numbers[7],Numbers[8])
def p1():
while True:
try:
main_input1 = int(raw_input("P1:Where do you want to go?"))
draw()
break
except:
print("Gimme a number")
main_input1 -= 1
if Numbers[main_input1]=="X" or Numbers[main_input1]=="O":
print("That is taken")
p1()
else:
Numbers[main_input1]=="X"
def p2():
while True:
try:
main_input2 = int(raw_input("P2:Where do you want to go?"))
draw()
break
except:
print("Gimme a number")
main_input2 -= 1
if Numbers[main_input2]=="X" or Numbers[main_input2]=="O":
print("That is taken")
p2()
else:
Numbers[main_input2]=="O"
def have_you_won():
for i in range(0,9):
if Win[i][1] == Win[i][2] and Win[i][2] == Win[3] and Win[i][1]=="X":
print("P1 has won")
elif Win[i][1] == Win[i][2] and Win[i][2] == Win[3] and Win[i][1]=="O":
print("P2 has won the game")
else:
return False
draw()
for i in range(0,10):
p1()
have_you_won()
p2()
have_you_won()
if i==9:
print("Its a tie!!")
tic_tac_toe()