{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4af84d7a",
   "metadata": {},
   "source": [
    "# 03-02 · Интерактивный режим (Python Shell)\n",
    "\n",
    "Практика к разделу [«Интерактивный режим Python (Python Shell)»](../../site/chapters/glava-03/03-02-interaktivny-rezhim.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96e33714",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Понять, чем интерактивная оболочка отличается от обычного файла — и заметить, что ноутбук Jupyter устроен очень похоже."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fd3be04",
   "metadata": {},
   "source": [
    "## Что нужно знать\n",
    "\n",
    "В Python Shell (`>>>`) каждая введённая строка сразу показывает результат."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c78effc",
   "metadata": {},
   "source": [
    "## Краткое напоминание\n",
    "\n",
    "В настоящей оболочке `>>> 2 + 2` тут же печатает `4` — без `print()`. Проверим, работает ли то же самое в ячейке Jupyter."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19d6ff7c",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c72648f6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:10.988957Z",
     "iopub.status.busy": "2026-08-14T20:52:10.988855Z",
     "iopub.status.idle": "2026-08-14T20:52:11.006681Z",
     "shell.execute_reply": "2026-08-14T20:52:11.006179Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 + 2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e72a467",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Сработало! Ячейка Jupyter, как и Python Shell, автоматически показывает результат **последнего**\n",
    "выражения в ячейке — и то, и другое построено на одной и той же идее REPL. Но это работает только\n",
    "для *последней* строки — проверим."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a3e1675a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:11.007809Z",
     "iopub.status.busy": "2026-08-14T20:52:11.007690Z",
     "iopub.status.idle": "2026-08-14T20:52:11.010722Z",
     "shell.execute_reply": "2026-08-14T20:52:11.010310Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 + 1\n",
    "2 + 2\n",
    "3 + 3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f57bb16",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "А если результат нужен на каждой строке — используем `print()`, как в обычном файле."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e799bca8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:11.011821Z",
     "iopub.status.busy": "2026-08-14T20:52:11.011689Z",
     "iopub.status.idle": "2026-08-14T20:52:11.014147Z",
     "shell.execute_reply": "2026-08-14T20:52:11.013696Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "4\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "print(1 + 1)\n",
    "print(2 + 2)\n",
    "print(3 + 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33ab90bb",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "В настоящей оболочке `>>> имя = \"Cartesian\"` **не** печатает результат — присваивание само по\n",
    "себе не является выражением со значением для показа. Начинающие иногда ждут вывод и после\n",
    "присваивания и удивляются, что его нет."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cc8def39",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:11.015146Z",
     "iopub.status.busy": "2026-08-14T20:52:11.015038Z",
     "iopub.status.idle": "2026-08-14T20:52:11.016973Z",
     "shell.execute_reply": "2026-08-14T20:52:11.016557Z"
    }
   },
   "outputs": [],
   "source": [
    "name = \"Cartesian\"  # ничего не выводится — это нормально"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9e24a41",
   "metadata": {},
   "source": [
    "## Исправление\n",
    "\n",
    "Чтобы увидеть значение переменной, нужно отдельно её вывести."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "081c6bc2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:11.017917Z",
     "iopub.status.busy": "2026-08-14T20:52:11.017820Z",
     "iopub.status.idle": "2026-08-14T20:52:11.019854Z",
     "shell.execute_reply": "2026-08-14T20:52:11.019388Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cartesian\n"
     ]
    }
   ],
   "source": [
    "name = \"Cartesian\"\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ee7a265",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "В одной ячейке напишите три арифметических выражения подряд и оберните каждое в `print()`, чтобы увидеть все три результата."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2da67db8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:11.020738Z",
     "iopub.status.busy": "2026-08-14T20:52:11.020640Z",
     "iopub.status.idle": "2026-08-14T20:52:11.022980Z",
     "shell.execute_reply": "2026-08-14T20:52:11.022481Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "5\n",
      "36\n"
     ]
    }
   ],
   "source": [
    "print(5 + 5)\n",
    "print(9 - 4)\n",
    "print(6 * 6)"
   ]
  }
 ],
 "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
}
