{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1520d7a0",
   "metadata": {},
   "source": [
    "# 04-10 · Деление, остаток и divmod()\n",
    "\n",
    "Практика к разделу [«Деление и остаток»](../../site/chapters/glava-04/04-10-delenie-i-ostatok.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b84a9a1",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить /, // и % на примере с конфетами, включая отрицательное floor-деление."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69baa324",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6bda5caf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:32.197201Z",
     "iopub.status.busy": "2026-08-16T10:03:32.197039Z",
     "iopub.status.idle": "2026-08-16T10:03:32.221783Z",
     "shell.execute_reply": "2026-08-16T10:03:32.221315Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "candies = 17\n",
    "children = 5\n",
    "print(candies // children)\n",
    "print(candies % children)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edaa7700",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Проверьте divmod() — он должен вернуть оба числа сразу."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7cf50827",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:32.222907Z",
     "iopub.status.busy": "2026-08-16T10:03:32.222798Z",
     "iopub.status.idle": "2026-08-16T10:03:32.224936Z",
     "shell.execute_reply": "2026-08-16T10:03:32.224550Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3, 2)\n"
     ]
    }
   ],
   "source": [
    "print(divmod(17, 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db298951",
   "metadata": {},
   "source": [
    "## Эксперимент 2 · 🚀 Чуть глубже\n",
    "\n",
    "Предскажите результат для отрицательного числа, затем проверьте."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3064cc17",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:32.226048Z",
     "iopub.status.busy": "2026-08-16T10:03:32.225950Z",
     "iopub.status.idle": "2026-08-16T10:03:32.228166Z",
     "shell.execute_reply": "2026-08-16T10:03:32.227723Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-3\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "print(-7 // 3)\n",
    "print(-7 % 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ba383ed",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "23 яблока делят между 4 корзинами поровну. Сколько яблок в каждой корзине и сколько останется?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a6f14b85",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:32.229075Z",
     "iopub.status.busy": "2026-08-16T10:03:32.228976Z",
     "iopub.status.idle": "2026-08-16T10:03:32.231051Z",
     "shell.execute_reply": "2026-08-16T10:03:32.230647Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 3\n"
     ]
    }
   ],
   "source": [
    "apples = 23\n",
    "baskets = 4\n",
    "per_basket = apples // baskets\n",
    "remainder = apples % baskets\n",
    "print(per_basket, remainder)"
   ]
  }
 ],
 "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
}
