I'm trying to draw a square randomly on a 700x700 grid however on each random run the square is drawn out of the boundary. How would I make it such that the whole square remains within the main grid boundary? Only the lower left of the square remains within the grid. I have this function below that draws a square randomly.
def draw_square():
""" Function to draw a square randomly on 700x700 grid """
turtle.penup()
turtle.setheading(0) # Make the turtle face east (0 degrees)
x = random.randint(-340, 340)
y = random.randint(-365, 315)
turtle.goto(x, y)
turtle.pendown() # Put the pen down
turtle.pensize(3) # Set the pen's width to 3 pixels
for i in range(4):
turtle.forward(100)
turtle.left(90)