{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "502ea2a3",
   "metadata": {},
   "source": [
    "# 13-03 · Возвращаем ответ\n",
    "\n",
    "Практика к разделу [«Возвращаем ответ»](../../site/chapters/glava-13/13-03-vozvrashaem-otvet.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cd80e2e9",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить return и разницу между return и print()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b5a9e82",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2f66798e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:36.850590Z",
     "iopub.status.busy": "2026-08-14T20:58:36.850439Z",
     "iopub.status.idle": "2026-08-14T20:58:36.885543Z",
     "shell.execute_reply": "2026-08-14T20:58:36.885042Z"
    }
   },
   "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": "df621e94",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — разница между print() и return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e894c571",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:36.886625Z",
     "iopub.status.busy": "2026-08-14T20:58:36.886502Z",
     "iopub.status.idle": "2026-08-14T20:58:36.888837Z",
     "shell.execute_reply": "2026-08-14T20:58:36.888483Z"
    }
   },
   "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": "33b35b09",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Напишите функцию `plosch_pryamougolnika(width, height)` — на этот раз с return вместо print(), и используйте результат."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cc12e6f0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:36.889882Z",
     "iopub.status.busy": "2026-08-14T20:58:36.889772Z",
     "iopub.status.idle": "2026-08-14T20:58:36.892365Z",
     "shell.execute_reply": "2026-08-14T20:58:36.891910Z"
    }
   },
   "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": "e3141780",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6fb3793e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:36.893662Z",
     "iopub.status.busy": "2026-08-14T20:58:36.893537Z",
     "iopub.status.idle": "2026-08-14T20:58:36.896068Z",
     "shell.execute_reply": "2026-08-14T20:58:36.895673Z"
    }
   },
   "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
}
