Code does not work in Python with turtle module : <p>I was creating a game in python with turtle and came across an error. The game's objective is to move your tank around and shoot enemy tanks. I am not finished yet. I added a white border, but when I tried to program the tank so that it could not go out of the boundaries, it does not work. Here is my code:</p>

<pre><code>#Import modules
import turtle
import time
import random

#Create screen
map = turtle.Screen()
map.bgcolor("limegreen")

#Create player tank
tank = turtle.Turtle()
tank.shape("triangle")
tank.color("blue")
tank.speed(0)
tank.penup()
tank.setposition(0, 0)
tank.setheading(90)

#Create border
borderPen = turtle.Turtle()
borderPen.speed(0)
borderPen.hideturtle()
borderPen.penup()
borderPen.setposition(-300, -300)
borderPen.color("white")
borderPen.pendown()

for sides in range(4):
  borderPen.fd(600)
  borderPen.lt(90)


#Define update coords function
global playerX
global playerY
global playerHeading
global tankSpeed
tankSpeed = 5

def update_coords():
  playerX = tank.xcor()
  playerY = tank.ycor()
  playerHeading = tank.heading()

#Define player movement functions
def move_forward():
  tank.fd(5)
  update_coords();
  if playerX &gt; 300 or playerX == 300:
    tank.setx(playerX - 5)
    update_coords();
  elif playerX &lt; -300 or playerX == -300:
    tank.setx(playerX + 5)
    update_coords();
  elif playerY &gt; 300 or playerY == 300:
    tank.sety(playerY - 5)
    update_coords();
  elif playerY &lt; -300 or playerY == -300:
    tank.sety(playerY + 5)
    update_coords();

def turn_left():
  tank.lt(10)

def turn_right():
  tank.rt(10)
#Allow player movement
map.listen()
map.onkey(move_forward, "Up")
map.onkey(turn_left, "Left")
map.onkey(turn_right, "Right")

#Create bullet
bullet = turtle.Turtle()
bullet.penup()
bullet.speed(0)
bullet.color("black")
bullet.hideturtle()
</code></pre>

<p>If you know why the code does not work, please respond. Thanks!</p>
