<s>[INST] import pygame
import random

# Initialize Pygame
pygame.init()
window = pygame.display.set_mode((800, 600))

# Set up some constants
WIDTH, HEIGHT = 800, 600
POS = [WIDTH / 2, HEIGHT / 2]

# Define some colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# Set up the display
pygame.display.set_caption("Bouncing Ball")
clock = pygame.time.Clock()

class Ball:
    def __init__(self):
        self.x, self.y = POS
        self.radius = 20
        self.color = RED
        self.speed_x = random.randint(-5, 5)
        self.speed_y = random.randint(-5, 5)

    def draw(self, screen):
        pygame.draw.circle(screen, self.color, (self.x, self.y), self.radius)

    def update(self):
        self.x += self.speed_x
        self.y += self.speed_y

        if self.x - self.radius < 0 or self.x + self.radius > WIDTH:
            self.speed_x *= -1
        if self.y - self.radius < 0 or self.y + self.radius > HEIGHT:
            self.speed_y *= -1

ball = Ball()

# Main game loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    window.fill(WHITE)
    ball.update()
    ball.draw(window)

    pygame.display.update()
    clock.tick(60)

This is code to create a bouncing ball in Pygame. However the bouncing ball goes off the screen for a brief moment before bouncing back. How can I fix this?[/INST]