I have tried to implement the snake game tutorial from the [link](https://theailearner.com/2018/10/06/creating-a-snake-game-with-pygame/) but the screen closes instantly after running the .py file. I have looked up for the screen instantly closing error and tried fixing it by adding a run block but now the screen just becomes black whenever I try to draw a rectangle.

```
import os
os.environ['SDL_AUDIODRIVER'] = 'dsp'
import pygame
import sys
import random
import subprocess

import pygame
pygame.init()

display_width = 500 
display_height = 500    
display = pygame.display.set_mode((display_width,display_height))
window_color= (200,200,200)
red = (255,0,0)  
black = (0,0,0)
apple_image = pygame.image.load('apple.jpg') 
snake_head = [250,250] 
pygame.display.set_caption("Snake AI")
snake_position = [[250,250],[240,250],[230,250]] 
apple_position = [random.randrange(1,50)*10,random.randrange(1,50)*10]

run = True
while run:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            run =False

        if event.type == pygame.KEYDOWN:
            command = "python sample.py"
            subprocess.call(command)

    def display_snake(snake_position):
        for position in snake_position:
            pygame.draw.rect(display,red,pygame.Rect(position[0],position[1],10,10))

    def display_apple(display,apple_position, apple):
        display.blit(apple,(apple_position[0], apple_position[1]))

    pygame.display.update()

pygame.quit()

```