Confusion about 'NamError'

i’ve give parameters and arguments to the function ‘ship’
however there is something wrong in tne function ‘alien_invasion’ namerror : ‘ai_settings’ is not defined
is it because i haven’t write the code 'ai_settings = ’ ?
thank u
here is the codes

import sys
import pygame
#from settings import Settings
from ship import Ship
import game_functions as gf

def run_game():
pygame.init()
screen = pygame.display.set_mode((1000,600))

pygame.display.set_caption("Alien Invasion")

bg_color = (230 , 230 , 230)

ship = Ship(screen , ai_settings)



while True :
    gf.check_events(ship)
    ship.update()
    screen.fill(bg_color)
    ship.blitme()

    pygame.display.flip()

run_game()

import pygame

class Ship():

def __init__(self , screen , ai_settings):
	self.screen = screen
	self.ai_settings = ai_settings
	self.image = pygame.image.load('ship.png')
	self.rect = self.image.get_rect()
	self.screen_rect = screen.get_rect()
	
	self.rect.centerx = self.screen_rect.centerx
	self.rect.bottom = self.screen_rect.bottom
	self.center = float(self.rect.centerx)
	self.moving_right = False
	self.moving_left = False
	
def update(self) :
	if self.moving_right:
		self.center += self.ai_settings.ship_speed_factor
	if self.moving_left:
		self.center -= self.ai_settings.ship_speed_factor
	
	self.rect.centerx = self.center
	
def blitme(self):
	self.screen.blit(self.image , self.rect)

Yes that is the reason, you have the correct analysis.

You cannot use a variable before you have defined it.