Make this code better

My python (turtle) code won't run

It's python (turtle) and what I'm supposed to do is create an interactive tic tac toe game. but every time I try to run it, it won't play correctly. i keep getting a "syntax error" or an "unexpected indent" but earlier everything had worked properly...

Tic Tac Toe Turtle
import turtle #I stayed up until twelve the last week to work on this on textWrangler and just am so tired please give me an A #tic tac toe box def setup_tictactoe(turtle): turtle.pensize(3) turtle.backward(120) for i in range(3): for m in range(3): for n in range(0,4): turtle.forward(80) turtle.right(90) turtle.forward(80) if i!=2: turtle.backward(80*3) turtle.left(90) turtle.forward(80) turtle.right(90) #I wanted to add some numbers in the boxes to make it easier turtle.pensize(1) turtle.penup() turtle.backward(78*3) turtle.right(90) turtle.forward(20) turtle.write("1", font=("Arial", 16, "normal")) turtle.left(90) turtle.forward(80) turtle.write("2", font=("Arial", 16, "normal")) turtle.forward(80) turtle.write("3", font=("Arial", 16, "normal")) turtle.right(90) turtle.forward(80) turtle.write("6", font=("Arial", 16, "normal")) turtle.right(90) turtle.forward(80) turtle.write("5", font=("Arial", 16, "normal")) turtle.forward(80) turtle.write("4", font=("Arial", 16, "normal")) turtle.left(90) turtle.forward(80) turtle.write("7", font=("Arial", 16, "normal")) turtle.left(90) turtle.forward(80) turtle.write("8", font=("Arial", 16, "normal")) turtle.forward(80) turtle.write("9", font=("Arial", 16, "normal")) #writes tic-tac-toe on the top of the game turtle.home() turtle.backward(95) turtle.left(90) turtle.forward(180) turtle.write("Tic-Tac-Toe", font=("Arial", 36, "normal")) #x def letter_x(turtle): turtle.left(45) turtle.pendown() turtle.forward(30) turtle.backward(60) turtle.forward(30) turtle.left(90) turtle.forward(30) turtle.backward(60) turtle.forward(30) turtle.penup() turtle.home() #o def circle_O(turtle): turtle.pendown() turtle.circle(30) turtle.penup() turtle.home() #variables and lists board = [1,2,3,4,5,6,7,8,9] counter=0 counter2=0 #screen screen=turtle.Screen() #backgroundcolor turtle.bgcolor("lightgreen") #turtle and board player=turtle.Turtle() player.speed(0) #faster player.shape("turtle") player.color("blue") setup_tictactoe(player) #adjusting turtle player.pensize(3) player.color("blue") player.penup() player.home() #introduction print("Hello friends, it is Tic Tac Toe time!") while counter!=1: #the counter will be 1, only if someone wins or if its a draw. counter2=counter2+1 #this counter will be used to control whose turn it is, based on if its even or odd. if its even its player two, odd is player 1 counter3=0 #this counter will be used to see if the number the user gave is usable, resets every loop while counter3==0: #it will keep looping until the number is usable if counter2%2 == 0: #if its even it will keeps track of who's turn it is. if counter2==2: user_number=int(input(("Player 2, its your turn!: "))) else: user_number=int(input(("Player 2 turn, please enter something : "))) if board[user_number-1]=="x" or board[user_number-1]=="o": #checking if the number they gave already is an x or an o print("Can you see that the box you are trying to use is not empty, try again") else: counter3=counter3+1 #adding one to counter so it knows that the number that is given is usable. else: #if counter number is odd then its player 1's turn if counter2==1: #if its their first turn, it gives the user more instruction than the other turns user_number=int(input(("Player 1, its your turn!: "))) else: user_number=int(input(("Player 1 turn, please enter the box number : "))) if board[user_number-1]=="x" or board[user_number-1]=="o" : #checking if the number they gave already is an x or an o. print("Can you see that the box you are trying to use is not empty, try again") else: counter3=counter3+1#adding one to counter so it knows that the number that is given is usable. number= board[user_number-1] #stores the number before it is turned into an X or O if counter2%2 == 0: #if counter is even then it's player two's turn. board[user_number-1]="x" #changes the number into an x else: #if its odd then player 1's turn board[user_number-1]="o" #changes the number into an O if counter2%2 == 0: #if counter is even then it's player two's turn. if number==1:#if number is 1 it goes through this loop # sets up the turtle to draw the letter X player.left(90) player.forward(120) player.right(90) player.backward(80) letter_x(player) #goes through all the winning possible combinations if they enter 1, and if its a match you add to your counter to end the game if board[1]=="x": if board[2]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[3]=="x": if board[6]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[8]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==2: #if number is 2 it goes through this loop # sets up the turtle to draw the letter X player.left(90) player.forward(120) letter_x(player) #goes through all the winning possible combinations if they enter 2, and if its a match you add to your counter to end the game if board[0]=="x": if board[2]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[7]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==3: #if number is 3 it goes through this loop # sets up the turtle to draw the letter X player.left(90) player.forward(120) player.right(90) player.forward(80) letter_x(player) #goes through all the possible winning combinations if they enter 3, and if its a match you add to your counter to end the game if board[1]=="x": if board[0]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[5]=="x": if board[8]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[6]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==4: #if number is 4 it goes through this loop # sets up the turtle to draw the letter X player.backward(80) player.left(90) player.forward(40) player.right(90) letter_x( player) #goes through all the possible winning combinations if they enter 4, and if its a match you add to your counter to end the game if board[0]=="x": if board[6]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[5]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==5: #if number is 5 it goes through this loop # sets up the turtle to draw the letter X player.left(90) player.forward(40) player.right(90) letter_x( player) #goes through all the possible winning combinations if they enter 5, and if its a match you add to your counter to end the game if board[1]=="x": if board[7]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[3]=="x": if board[5]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[0]=="x": if board[8]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[2]=="x": if board[6]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==6: #if number is 6 it goes through this loop # sets up the turtle to draw the letter X player.forward(80) player.left(90) player.forward(40) player.right(90) letter_x(player) #goes through all the possible winning combinations if they enter 6, and if its a match you add to your counter to end the game if board[2]=="x": if board[8]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[3]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif board[4]=="x": if board[6]=="x": print("Congrats Player Two, You Win!") counter=counter+1 elif number==7: #if number is 7 it goes through this loop # sets up the turtle to draw the letter X player.backward(80) player.right(90) player.forward(40) player.left(90) letter_x(player) #goes through all the possible winning combinations if they enter 7, and if its a match you add to your counter to end the game if board[7]=="x": if board[8]=="x": print("You Win") counter=counter+1 elif board[0]=="x": if board[3]=="x": print("You Win") counter=counter+1 elif board[4]=="x": if board[2]=="x": print("You Win") counter=counter+1 elif number==8: #if number is 8 it goes through this loop # sets up the turtle to draw the letter X player.right(90) player.forward(40) player.left(90) letter_x(player) #goes through all the possible winning combinations if they enter 8, and if its a match you add to your counter to end the game if board[4]=="x": if board[1]=="x": print("You Win") counter=counter+1 elif board[6]=="x": if board[8]=="x": print("You Win") counter=counter+1 elif board[4]=="x": if board[2]=="x": print("You Win") counter=counter+1 elif number==9: #if number is 9 it goes through this loop # sets up the turtle to draw the letter X player.forward(80) player.right(90) player.forward(40) player.left(90) letter_x(player) #goes through all the possible winning combinations if they enter 9,and if its a match you add to your counter to end the game if board[5]=="x": if board[2]=="x": print("You Win") counter=counter+1 elif board[4]=="x": if board[0]=="x": print("You Win") counter=counter+1 elif board[7]=="x": if board[6]=="x": print("You Win") counter=counter+1 else: # if its player 1's turn if number==1: #if number is 1 it goes through this loop # sets up the turtle to draw the letter O player.penup() player.left(90) player.forward(150) player.left(90) player.forward(80) circle_O(player) #goes through all the possible winning combinations if they enter 1,and if its a match you add to your counter to end the game if board[1]=="o": if board[2]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[3]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==2:#if number is 2 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.forward(150) player.left(90) circle_O(player) #goes through all the possible winning combinations if they enter 2, and if its a match you add to your counter to end the game if board[0]=="o": if board[2]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[7]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==3:#if number is 3 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.forward(150) player.right(90) player.forward(80) player.left(180) circle_O(player) #goes through all the possible winning combinations if they enter 3,and if its a match you add to your counter to end the game if board[1]=="o": if board[0]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[5]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==4:#if number is 4 it goes through this loop # sets up the turtle to draw the letter O player.backward(80) player.left(90) player.forward(70) player.left(90) circle_O(player) #goes through all the possible winning combinations if they enter 4,and if its a match you add to your counter to end the game if board[0]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[5]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==5:#if number is 5 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.forward(70) player.left(90) circle_O(player) #goes through all the possible winning combinations if they enter 5,and if its a match you add to your counter to end the game if board[1]=="o": if board[7]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[3]=="o": if board[5]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[0]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[2]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==6:#if number is 6 it goes through this loop # sets up the turtle to draw the letter O player.forward(80) player.left(90) player.forward(70) player.left(90) circle_O(player) #goes through all the possible winning combinations if they enter 6,and if its a match you add to your counter to end the game if board[2]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[3]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==7:#if number is 7 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.backward(70) player.right(90) player.backward(80) circle_O(player) #goes through all the possible winning combinations if they enter 7,and if its a match you add to your counter to end the game if board[7]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[0]=="o": if board[3]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[2]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==8:#if number is 8 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.backward(70) player.right(90) circle_O(player) #goes through all the possible winning combinations if theyu enter 8,and if its a match you add to your counter to end the game if board[4]=="o": if board[1]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[6]=="o": if board[8]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[2]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif number==9:#if number is 9 it goes through this loop # sets up the turtle to draw the letter O player.left(90) player.backward(70) player.right(90) player.forward(80) circle_O(player) #goes through all the possible winning combinations if they enter 9,and if its a match you add to your counter to end the game if board[5]=="o": if board[2]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[4]=="o": if board[0]=="o": print("Congrats Player One, You Win!") counter=counter+1 elif board[7]=="o": if board[6]=="o": print("Congrats Player One, You Win!") counter=counter+1 # this loop checks if its a draw by seeing if all the boxes are filled with X's or O's. If they are it adds to the counter to finish the game if counter!=1: if board[0]=="x" or board[0]=="o": if board[1]=="x" or board[1]=="o": if board[2]=="x" or board[2]=="o": if board[3]=="x" or board[3]=="o": if board[4]=="x" or board[4]=="o": if board[5]=="x" or board[5]=="o": if board[6]=="x" or board[6]=="o": if board[7]=="x" or board[7]=="o": if board[8]=="x" or board[8]=="o": print("Its a Draw") counter= counter+1

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.