Mar-30-2018, 09:32 PM
i crated a simple tic tac toe game in python and it keeps telling me i have an indentation problem i will appreciate if someone would be able to help me. here's the code of the game:
![[Image: f0ea22cbd5b487a605ccbba29ad5943f.png]](https://i.gyazo.com/f0ea22cbd5b487a605ccbba29ad5943f.png)
![[Image: 29cab16e9bb2f16fb173f9b7440a20f7.png]](https://i.gyazo.com/29cab16e9bb2f16fb173f9b7440a20f7.png)
![[Image: f0ea22cbd5b487a605ccbba29ad5943f.png]](https://i.gyazo.com/f0ea22cbd5b487a605ccbba29ad5943f.png)
![[Image: 29cab16e9bb2f16fb173f9b7440a20f7.png]](https://i.gyazo.com/29cab16e9bb2f16fb173f9b7440a20f7.png)
def printboard(a,b,c): print(a) print(b) print(c) def draw(*biglist): draww=true for i in biglist: if i=="": draww=false else: pass return draww def winner(a,b,c): iswinner=false if a[0]=="X" and a[1]=="X" and a[2]=="X": iswinner=true elif b[0]=="X" and b[1]=="X" and b[2]=="X": iswinner=true elif c[0]=="X" and c[1]=="X" and c[2]=="X": iswinner=true elif a[0]=="X" and b[0]=="X" and c[0]=="X": iswinner=true elif a[1]=="X" and b[1]=="X" and c[1]=="X": iswinner=true elif a[2]=="X" and b[2]=="X" and c[2]=="X": iswinner=true elif a[0]=="X" and b[1]=="X" and c[2]=="X": iswinner=true elif a[2]=="X" and b[1]=="X" and c[0]=="X": iswinner=true elif a[0]=="O" and a[1]=="O" and a[2]=="O": iswinner=true elif b[0]=="O" and b[1]=="O" and b[2]=="O": iswinner=true elif c[0]=="O" and c[1]=="O" and c[2]=="O": iswinner=true elif a[0]=="O" and b[0]=="O" and c[0]=="O": iswinner=true elif a[1]=="O" and b[1]=="O" and c[1]=="O": iswinner=true elif a[2]=="O" and b[2]=="O" and c[2]=="O": iswinner=true elif a[0]=="O" and b[1]=="O" and c[2]=="O": iswinner=true elif a[2]=="O" and b[1]=="O" and c[0]=="O": iswinner=true return iswinner gameon=true player1=input("do you want to be X or O") turn=1 if player1=="X": player2="O" else: player2="X" list1=["","",""] list2=["","",""] list3=["","",""] print("enjoy the game") printboard(list1,list2,list3) while gameon: if turn%2!=0: player="player1" answer=input("chose the location you want to insert player1 (1-9)") else: player="player2" answer=input("chose the location you want to insert player2 (1-9)") if player=="player1": if answer>=1 and answer<=3: list1[answer-1]=player1 elif answer>=4 and answer<=6: list2[answer-4]=player1 else: list3[answer-7]=player1 else: if answer>=1 and answer<=3: list1[answer-1]=player1 elif answer>=4 and answer<=6: list2[answer-4]=player2 else: list3[answer-7]=player3 if draw(list1,list2,list3): print("its a draw") gameon=false if winner(list1,list2,list3): if turn%2==0: print("the winner is player 2") gameon=false else: print("the winner is player 1") gameon=false
if player1=="X": player2="O" else: player2="X"Indentation is off, should be 4 spaces.
if player=="player1": if answer>=1 and answer<=3: list1[answer-1]=player1 elif answer>=4 and answer<=6: list2[answer-4]=player1 else: list3[answer-7]=player1 else: if answer>=1 and answer<=3: list1[answer-1]=player1 elif answer>=4 and answer<=6: list2[answer-4]=player2 else: list3[answer-7]=player3 if draw(list1,list2,list3): print("its a draw") gameon=false if winner(list1,list2,list3): if turn%2==0: print("the winner is player 2") gameon=false else: print("the winner is player 1") gameon=false
if player=="player1": if answer>=1 and answer<=3: list1[answer-1]=player1 elif answer>=4 and answer<=6: list2[answer-4]=player1 else: list3[answer-7]=player1has 8, not 4
Error:File "<tokenize>", line 75
if player=="player1":
^
IndentationError: unindent does not match any outer indentation level
Quote:IndentationError: unindent does not match any outer indentation levelif player=="player1": is at a different indentation level than if turn%2!=0: (outer indentation level) Again, it could be mixing tabs and spaces that causes this. Most editors have a "replace tabs with spaces" option.