{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f3166d33",
   "metadata": {},
   "source": [
    "# 04-15 · round, floor, ceil, trunc\n",
    "\n",
    "Практика к разделу [«Округление»](../../site/chapters/glava-04/04-15-okruglenie.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fa1587f",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Предсказывать результат разных способов округления, особенно для отрицательных чисел."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46561458",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f953efe2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:42.035473Z",
     "iopub.status.busy": "2026-08-16T10:03:42.035339Z",
     "iopub.status.idle": "2026-08-16T10:03:42.057510Z",
     "shell.execute_reply": "2026-08-16T10:03:42.057035Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.14\n"
     ]
    }
   ],
   "source": [
    "print(round(3.14159, 2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0fb08442",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Округление до чётного — предскажите оба результата."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f42fdebf",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:42.058467Z",
     "iopub.status.busy": "2026-08-16T10:03:42.058356Z",
     "iopub.status.idle": "2026-08-16T10:03:42.060552Z",
     "shell.execute_reply": "2026-08-16T10:03:42.060127Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "print(round(2.5))\n",
    "print(round(3.5))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2faea06",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "Предскажите floor/ceil/trunc для отрицательного числа."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3d69a077",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:42.061551Z",
     "iopub.status.busy": "2026-08-16T10:03:42.061392Z",
     "iopub.status.idle": "2026-08-16T10:03:42.063525Z",
     "shell.execute_reply": "2026-08-16T10:03:42.063214Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-3\n",
      "-2\n",
      "-2\n"
     ]
    }
   ],
   "source": [
    "from math import floor, ceil, trunc\n",
    "print(floor(-2.3))\n",
    "print(ceil(-2.3))\n",
    "print(trunc(-2.3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bad6408",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Округлите 7.4567 до 2 знаков после запятой."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d7f181fb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T10:03:42.064557Z",
     "iopub.status.busy": "2026-08-16T10:03:42.064456Z",
     "iopub.status.idle": "2026-08-16T10:03:42.066437Z",
     "shell.execute_reply": "2026-08-16T10:03:42.066028Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7.46\n"
     ]
    }
   ],
   "source": [
    "print(round(7.4567, 2))"
   ]
  }
 ],
 "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
}
