{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "68dd1828",
   "metadata": {},
   "source": [
    "# 03-08 · Прочитайте traceback: NameError\n",
    "\n",
    "Практика к разделу [«Ошибки, traceback и как их читать»](../../site/chapters/glava-03/03-13-oshibki-i-traceback.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53613a0f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Научиться спокойно читать `NameError` и находить причину по traceback, а не пугаться красного текста."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3763f07",
   "metadata": {},
   "source": [
    "## Что нужно знать\n",
    "\n",
    "`NameError` означает: Python встретил имя, которое ещё нигде не было создано присваиванием."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d8dcb4a",
   "metadata": {},
   "source": [
    "## Краткое напоминание\n",
    "\n",
    "Последняя строка traceback — самая важная: в ней указан тип ошибки и краткое объяснение."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "468da783",
   "metadata": {},
   "source": [
    "## Разминка\n",
    "\n",
    "Прежде чем смотреть на ошибку, запустите одну рабочую ячейку — чтобы Python-среда точно была готова."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "311c4f4d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:21.964759Z",
     "iopub.status.busy": "2026-08-16T02:04:21.964651Z",
     "iopub.status.idle": "2026-08-16T02:04:21.981306Z",
     "shell.execute_reply": "2026-08-16T02:04:21.980819Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Готовы искать ошибки!\n"
     ]
    }
   ],
   "source": [
    "print(\"Готовы искать ошибки!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd73d1b0",
   "metadata": {},
   "source": [
    "## Рабочий пример\n",
    "\n",
    "Запустите — и внимательно прочитайте последнюю строку вывода."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f81ad8a2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:21.982246Z",
     "iopub.status.busy": "2026-08-16T02:04:21.982133Z",
     "iopub.status.idle": "2026-08-16T02:04:22.010154Z",
     "shell.execute_reply": "2026-08-16T02:04:22.009605Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'usr_name' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[2]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m print(usr_name)\n",
      "\u001b[31mNameError\u001b[39m: name 'usr_name' is not defined"
     ]
    }
   ],
   "source": [
    "print(usr_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f929d1ad",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Это опечатка в имени переменной — очень частая причина `NameError` у новичков. Найдите опечатку и исправьте её."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d56ec285",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:22.011217Z",
     "iopub.status.busy": "2026-08-16T02:04:22.011108Z",
     "iopub.status.idle": "2026-08-16T02:04:22.018080Z",
     "shell.execute_reply": "2026-08-16T02:04:22.017614Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'usr_name' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m user_name = \u001b[33m\"Cartesian\"\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m print(usr_name)\n",
      "\u001b[31mNameError\u001b[39m: name 'usr_name' is not defined"
     ]
    }
   ],
   "source": [
    "user_name = \"Cartesian\"\n",
    "print(usr_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86182e77",
   "metadata": {},
   "source": [
    "## Исправление"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7bfdf4d3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:22.019086Z",
     "iopub.status.busy": "2026-08-16T02:04:22.018921Z",
     "iopub.status.idle": "2026-08-16T02:04:22.021308Z",
     "shell.execute_reply": "2026-08-16T02:04:22.020845Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cartesian\n"
     ]
    }
   ],
   "source": [
    "user_name = \"Cartesian\"\n",
    "print(user_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6f20a95",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "В ячейке ниже есть та же ошибка — переменная называется `score`, а выводится `scroe`. Исправьте опечатку, ничего больше не меняя."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5fbfed46",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:22.022223Z",
     "iopub.status.busy": "2026-08-16T02:04:22.022124Z",
     "iopub.status.idle": "2026-08-16T02:04:22.029112Z",
     "shell.execute_reply": "2026-08-16T02:04:22.028623Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'scroe' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m score = \u001b[32m100\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m print(scroe)\n",
      "\u001b[31mNameError\u001b[39m: name 'scroe' is not defined"
     ]
    }
   ],
   "source": [
    "score = 100\n",
    "print(scroe)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "45ba1337",
   "metadata": {},
   "source": [
    "## Решение задания"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2fc825ef",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T02:04:22.030132Z",
     "iopub.status.busy": "2026-08-16T02:04:22.029958Z",
     "iopub.status.idle": "2026-08-16T02:04:22.032114Z",
     "shell.execute_reply": "2026-08-16T02:04:22.031710Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100\n"
     ]
    }
   ],
   "source": [
    "score = 100\n",
    "print(score)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
