{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e96837c9",
   "metadata": {},
   "source": [
    "# 13-03 · Возвращаем ответ\n",
    "\n",
    "Практика к разделу [«Возвращаем ответ»](../../site/chapters/glava-13/13-03-vozvrashaem-otvet.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e1f033",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить return и разницу между return и print()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1eae2ef",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "eb0981a3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:39.793840Z",
     "iopub.status.busy": "2026-08-17T18:53:39.793683Z",
     "iopub.status.idle": "2026-08-17T18:53:39.816883Z",
     "shell.execute_reply": "2026-08-17T18:53:39.816338Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "50\n"
     ]
    }
   ],
   "source": [
    "def summa(a, b):\n",
    "    return a + b\n",
    "\n",
    "result = summa(5, 7)\n",
    "print(result)\n",
    "print(summa(2, 3) * 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "397432d3",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — разница между print() и return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b286e402",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:39.818356Z",
     "iopub.status.busy": "2026-08-17T18:53:39.818227Z",
     "iopub.status.idle": "2026-08-17T18:53:39.820872Z",
     "shell.execute_reply": "2026-08-17T18:53:39.820495Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "x = None\n"
     ]
    }
   ],
   "source": [
    "def summa_pechataet(a, b):\n",
    "    print(a + b)\n",
    "\n",
    "x = summa_pechataet(5, 7)\n",
    "print(\"x =\", x)  # None — функция ничего не вернула!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "19a6d2fb",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Напишите функцию `plosch_pryamougolnika(width, height)` — на этот раз с return вместо print(), и используйте результат."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3af97f7b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:39.822120Z",
     "iopub.status.busy": "2026-08-17T18:53:39.821943Z",
     "iopub.status.idle": "2026-08-17T18:53:39.824428Z",
     "shell.execute_reply": "2026-08-17T18:53:39.824007Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Первая площадь: 15, вторая: 100, сумма площадей: 115\n"
     ]
    }
   ],
   "source": [
    "def plosch_pryamougolnika(width, height):\n",
    "    return width * height\n",
    "\n",
    "a1 = plosch_pryamougolnika(5, 3)\n",
    "a2 = plosch_pryamougolnika(10, 10)\n",
    "print(f\"Первая площадь: {a1}, вторая: {a2}, сумма площадей: {a1 + a2}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e3145e5",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "08545c3b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:39.825639Z",
     "iopub.status.busy": "2026-08-17T18:53:39.825454Z",
     "iopub.status.idle": "2026-08-17T18:53:39.829220Z",
     "shell.execute_reply": "2026-08-17T18:53:39.828595Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Обе проверки пройдены.\n"
     ]
    }
   ],
   "source": [
    "def plosch_pryamougolnika(width, height):\n",
    "    return width * height\n",
    "\n",
    "assert plosch_pryamougolnika(5, 3) == 15\n",
    "assert plosch_pryamougolnika(10, 10) == 100\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
}
