{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b344396d",
   "metadata": {},
   "source": [
    "# 05-04 · Математические функции\n",
    "\n",
    "Практика к разделу [«Интересные возможности работы с числами»](../../site/chapters/glava-05/05-04-matematicheskie-funkcii.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9b8c9b72",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить модуль `math`: floor, ceil, sqrt, factorial, тригонометрию."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba2bad98",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "df05562f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:18.488056Z",
     "iopub.status.busy": "2026-08-14T20:52:18.487942Z",
     "iopub.status.idle": "2026-08-14T20:52:18.505643Z",
     "shell.execute_reply": "2026-08-14T20:52:18.505046Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "5\n",
      "8.0\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "print(math.floor(4.7))\n",
    "print(math.ceil(4.2))\n",
    "print(math.sqrt(64))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6f36c65",
   "metadata": {},
   "source": [
    "## Эксперимент 1\n",
    "\n",
    "Посчитайте факториалы нескольких чисел подряд."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0ade9001",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:18.507057Z",
     "iopub.status.busy": "2026-08-14T20:52:18.506895Z",
     "iopub.status.idle": "2026-08-14T20:52:18.510538Z",
     "shell.execute_reply": "2026-08-14T20:52:18.509985Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 ! = 1\n",
      "2 ! = 2\n",
      "3 ! = 6\n",
      "4 ! = 24\n",
      "5 ! = 120\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "for n in range(1, 6):\n",
    "    print(n, \"! =\", math.factorial(n))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "997ef726",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "`round()` — встроенная функция (не из math). Сравните её с floor/ceil на одном и том же числе."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "032cae24",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:18.511543Z",
     "iopub.status.busy": "2026-08-14T20:52:18.511406Z",
     "iopub.status.idle": "2026-08-14T20:52:18.513748Z",
     "shell.execute_reply": "2026-08-14T20:52:18.513337Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4 4 5\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "x = 4.5\n",
    "print(round(x), math.floor(x), math.ceil(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06537506",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Найдите длину гипотенузы прямоугольного треугольника с катетами 3 и 4, используя `math.sqrt`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9f38c429",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:18.514714Z",
     "iopub.status.busy": "2026-08-14T20:52:18.514613Z",
     "iopub.status.idle": "2026-08-14T20:52:18.516900Z",
     "shell.execute_reply": "2026-08-14T20:52:18.516579Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "a, b = 3, 4\n",
    "hypotenuse = math.sqrt(a ** 2 + b ** 2)\n",
    "print(hypotenuse)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9935f83c",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e72167bb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:18.518014Z",
     "iopub.status.busy": "2026-08-14T20:52:18.517908Z",
     "iopub.status.idle": "2026-08-14T20:52:18.520145Z",
     "shell.execute_reply": "2026-08-14T20:52:18.519817Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: классический треугольник 3-4-5.\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "assert math.sqrt(3 ** 2 + 4 ** 2) == 5.0\n",
    "print(\"Верно: классический треугольник 3-4-5.\")"
   ]
  }
 ],
 "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
}
