"screen" is not defined

im just started learning python with “Python crash course”
and there is code in this book, but it’s not working, or probably i’m missing smt
in line “self.ship = Ship(screen)” there is an error:
Traceback (most recent call last):
File “c:\Users\Куку\Desktop\Space Invaders\first_step.py”, line 40, in
ai = AlienInvasion()
^^^^^^^^^^^^^^^
File “c:\Users\Куку\Desktop\Space Invaders\first_step.py”, line 23, in init
self.ship = Ship(screen)
^^^^^^
NameError: name ‘screen’ is not defined. Did you mean: ‘self.screen’?

My code:

import sys

import pygame

from settings import Settings

from ship import Ship


class AlienInvasion:
    def __init__(self):
        """
        The function initializes the Pygame module and sets up the game window.
        """
        pygame.init()
        self.settings = Settings()

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height)
        )
        pygame.display.set_caption("Alien Invasion")

        self.ship = Ship(screen)

    def run_game(self):
        while True:
            # Отслеживание событий клавиатуры и мыши
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
            # При каждом проходе цикла перерисовывается экран
            self.screen.fill(self.settings.bg_color)
            self.ship.blitme()
            # Отображение последнего прорисованного экрана
            pygame.display.flip()


if __name__ == "__main__":
    # Создание экземпляра и запуск игры
    ai = AlienInvasion()
    ai.run_game()

code for class Ship

import pygame


class Ship:
    """Класс для управления кораблем"""


def __init__(self, ai_game, screen):
    """Инициализация корабля и его начально позиции"""
    self.screen = ai_game.screen
    self.screen_rect = ai_game.screen.get_rect()
    # Загружает изображение корабля и получает прямоугольник
    self.image = pygame.image.load("images/ship.bmp")
    self.rect = self.image.get_rect()
    self.rect.midbottom = self.screen_rect.midbottom


def blitme(self):
    """Отрисовка корабля"""
    self.screen.blit(self.image, self.rect)

code for settings

class Settings():
    def __init__(self):
        """Инициализация параметров игры."""
        # Параметры экрана
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (248, 124, 86)
        

What i need to change

The error says that there is no screen in the scope where that line is executed. There is self.screen. You need to check if that is what you want, but try self.ship = Ship(self.screen)

The error message suggests this too “Did you mean: ‘self.screen’?”

yep, i tried that, but
TypeError: Ship() takes no arguments

You didn’t indent the methods in the Ship class.
Having done that, you’ll find that you have to call it with two arguments although I think you won’t need the last one.

Oh, now I did indent, but there is still this error

Now if type “self.ship = Ship(self.screen)” there are new errors

Traceback (most recent call last):
  File "c:\Users\Куку\Desktop\Space Invaders\first_step.py", line 40, in <module>
    ai = AlienInvasion()
         ^^^^^^^^^^^^^^^
  File "c:\Users\Куку\Desktop\Space Invaders\first_step.py", line 23, in __init__
    self.ship = Ship(self.screen)
                ^^^^^^^^^^^^^^^^^
  File "c:\Users\Куку\Desktop\Space Invaders\ship.py", line 9, in __init__
    self.screen = ai_game.screen
                  ^^^^^^^^^^^^^^
AttributeError: 'pygame.surface.Surface' object has no attribute 'screen'

This means: when you create a Ship, you need to tell it what ai_game to use, and what screen to use, in that order.

This means: create a new Ship, and use the self.screen. But you didn’t mention a value for ai_game.

Code in books is often wrong. You need to read the rest of the text, in between the code, in order to understand the concepts used in the code. You should also practice reading and understanding error messages, because you can’t always just type in someone else’s code (in fact, you can basically never do this; real programmers use each others’ code all the time, but not by typing it in).