{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "eb6f4283",
   "metadata": {},
   "source": [
    "# 19-10 · Координаты клетки и пиксели Turtle\n",
    "\n",
    "Практика к разделу [«Координаты клетки и пиксели Turtle»](../../site/chapters/glava-19/19-10-koordinaty-kletki.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80e99f2f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Перевести пиксельные координаты в клетку, аккуратно с отрицательными числами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a680dd01",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a869fbcb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:39.156886Z",
     "iopub.status.busy": "2026-09-03T00:53:39.156703Z",
     "iopub.status.idle": "2026-09-03T00:53:39.189889Z",
     "shell.execute_reply": "2026-09-03T00:53:39.189267Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, 3)\n",
      "(-1, 0)\n"
     ]
    }
   ],
   "source": [
    "STEP = 20\n",
    "\n",
    "def pixel_to_cell(x, y, step=STEP):\n",
    "    return x // step, y // step\n",
    "\n",
    "print(pixel_to_cell(40, 60))\n",
    "print(pixel_to_cell(-10, 0))   # округление вниз, не к нулю!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a33879e6",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c452db26",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T00:53:39.191374Z",
     "iopub.status.busy": "2026-09-03T00:53:39.191151Z",
     "iopub.status.idle": "2026-09-03T00:53:39.194749Z",
     "shell.execute_reply": "2026-09-03T00:53:39.193736Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Отрицательные координаты переведены верно.\n"
     ]
    }
   ],
   "source": [
    "assert pixel_to_cell(40, 60) == (2, 3)\n",
    "assert pixel_to_cell(-10, 0) == (-1, 0)\n",
    "assert pixel_to_cell(-20, 0) == (-1, 0)\n",
    "assert pixel_to_cell(-21, 0) == (-2, 0)\n",
    "print(\"Отрицательные координаты переведены верно.\")"
   ]
  }
 ],
 "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
}
