{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1c851e94",
   "metadata": {},
   "source": [
    "# 05-02 · Специальные операции, присваивание и порядок\n",
    "\n",
    "Практика к разделам [«Специальные операции»](../../site/chapters/glava-05/05-02-specialnye-operacii.html) и [«Присваивание и порядок»](../../site/chapters/glava-05/05-03-prisvaivanie-poryadok.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c5dcd4e",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить //, %, ** и сокращённые операторы присваивания."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c1533eb",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5ec13fbc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.683171Z",
     "iopub.status.busy": "2026-08-14T20:52:17.682952Z",
     "iopub.status.idle": "2026-08-14T20:52:17.701510Z",
     "shell.execute_reply": "2026-08-14T20:52:17.701042Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "2\n",
      "1024\n"
     ]
    }
   ],
   "source": [
    "print(17 // 5)\n",
    "print(17 % 5)\n",
    "print(2 ** 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ecf7297",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Проверьте чётность нескольких чисел через `% 2`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c602980b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.702676Z",
     "iopub.status.busy": "2026-08-14T20:52:17.702524Z",
     "iopub.status.idle": "2026-08-14T20:52:17.705926Z",
     "shell.execute_reply": "2026-08-14T20:52:17.705468Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 True\n",
      "7 False\n",
      "10 True\n",
      "13 False\n"
     ]
    }
   ],
   "source": [
    "for n in [4, 7, 10, 13]:\n",
    "    print(n, n % 2 == 0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5140707",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "Используйте `+=` для накопления счёта в игре за три хода."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2c3577f8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.707022Z",
     "iopub.status.busy": "2026-08-14T20:52:17.706902Z",
     "iopub.status.idle": "2026-08-14T20:52:17.709598Z",
     "shell.execute_reply": "2026-08-14T20:52:17.708931Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "42\n"
     ]
    }
   ],
   "source": [
    "score = 0\n",
    "score += 10\n",
    "score += 25\n",
    "score += 7\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "061d3dff",
   "metadata": {},
   "source": [
    "## Типичная ошибка\n",
    "\n",
    "Легко перепутать `//` (целочисленное деление) и `/` (обычное) — они дают разные типы результата."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3ab8860a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.711032Z",
     "iopub.status.busy": "2026-08-14T20:52:17.710848Z",
     "iopub.status.idle": "2026-08-14T20:52:17.713282Z",
     "shell.execute_reply": "2026-08-14T20:52:17.712879Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 <class 'int'>\n",
      "3.3333333333333335 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "print(10 // 3, type(10 // 3))\n",
    "print(10 / 3, type(10 / 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85e7c30e",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Проверьте порядок вычислений: посчитайте `2 + 3 * 4 ** 2` и сравните со своим предсказанием на бумаге."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b96f7fb7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.714252Z",
     "iopub.status.busy": "2026-08-14T20:52:17.714143Z",
     "iopub.status.idle": "2026-08-14T20:52:17.716263Z",
     "shell.execute_reply": "2026-08-14T20:52:17.715847Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50\n"
     ]
    }
   ],
   "source": [
    "print(2 + 3 * 4 ** 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b738d68",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2c4eb887",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:17.717197Z",
     "iopub.status.busy": "2026-08-14T20:52:17.717094Z",
     "iopub.status.idle": "2026-08-14T20:52:17.719414Z",
     "shell.execute_reply": "2026-08-14T20:52:17.718858Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: 4 ** 2 = 16, 3 * 16 = 48, 48 + 2 = 50\n"
     ]
    }
   ],
   "source": [
    "assert 2 + 3 * 4 ** 2 == 50\n",
    "print(\"Верно: 4 ** 2 = 16, 3 * 16 = 48, 48 + 2 = 50\")"
   ]
  }
 ],
 "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
}
