{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "698bb5fa",
   "metadata": {},
   "source": [
    "# 09-03 · if / else\n",
    "\n",
    "Практика к разделу [«Если это произошло — выполни команду!»](../../site/chapters/glava-09/09-03-if-inache.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "68fc767c",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить условный оператор if и его альтернативу else."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e54e0aee",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3713a9b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.151096Z",
     "iopub.status.busy": "2026-08-14T20:53:54.150979Z",
     "iopub.status.idle": "2026-08-14T20:53:54.181550Z",
     "shell.execute_reply": "2026-08-14T20:53:54.181014Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Доступ разрешён.\n"
     ]
    }
   ],
   "source": [
    "age = 20\n",
    "if age >= 18:\n",
    "    print(\"Доступ разрешён.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbee7ce2",
   "metadata": {},
   "source": [
    "## Эксперимент 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "651455e5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.182881Z",
     "iopub.status.busy": "2026-08-14T20:53:54.182753Z",
     "iopub.status.idle": "2026-08-14T20:53:54.185210Z",
     "shell.execute_reply": "2026-08-14T20:53:54.184747Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Доступ запрещён — вам ещё нет 18.\n"
     ]
    }
   ],
   "source": [
    "age = 15\n",
    "if age >= 18:\n",
    "    print(\"Доступ разрешён.\")\n",
    "else:\n",
    "    print(\"Доступ запрещён — вам ещё нет 18.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe41a530",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Пропущенный отступ вызывает IndentationError."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "47e4de22",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.186117Z",
     "iopub.status.busy": "2026-08-14T20:53:54.186006Z",
     "iopub.status.idle": "2026-08-14T20:53:54.188492Z",
     "shell.execute_reply": "2026-08-14T20:53:54.188088Z"
    },
    "tags": [
     "raises-exception"
    ]
   },
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "expected an indented block after 'if' statement on line 2 (3251843816.py, line 3)",
     "output_type": "error",
     "traceback": [
      "  \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[3]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[31m    \u001b[39m\u001b[31mprint(\"Доступ разрешён.\")\u001b[39m\n    ^\n\u001b[31mIndentationError\u001b[39m\u001b[31m:\u001b[39m expected an indented block after 'if' statement on line 2\n"
     ]
    }
   ],
   "source": [
    "age = 20\n",
    "if age >= 18:\n",
    "print(\"Доступ разрешён.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16dbd502",
   "metadata": {},
   "source": [
    "## Исправление"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8f608064",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.189491Z",
     "iopub.status.busy": "2026-08-14T20:53:54.189391Z",
     "iopub.status.idle": "2026-08-14T20:53:54.191633Z",
     "shell.execute_reply": "2026-08-14T20:53:54.191166Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Доступ разрешён.\n"
     ]
    }
   ],
   "source": [
    "age = 20\n",
    "if age >= 18:\n",
    "    print(\"Доступ разрешён.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c742b8b",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Напишите проверку чётности числа с if/else (используем `%` из главы 5)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ee7fe125",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.192893Z",
     "iopub.status.busy": "2026-08-14T20:53:54.192720Z",
     "iopub.status.idle": "2026-08-14T20:53:54.195823Z",
     "shell.execute_reply": "2026-08-14T20:53:54.195201Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17 — нечётное\n"
     ]
    }
   ],
   "source": [
    "number = 17\n",
    "if number % 2 == 0:\n",
    "    print(f\"{number} — чётное\")\n",
    "else:\n",
    "    print(f\"{number} — нечётное\")"
   ]
  }
 ],
 "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
}
