{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1e6a093e",
   "metadata": {},
   "source": [
    "# 13-04 · Аргументы функций\n",
    "\n",
    "Практика к разделу [«Нет аргументов? Слишком много аргументов!»](../../site/chapters/glava-13/13-04-argumenty.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8225ccfb",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить значения по умолчанию и *args."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a98f8bc1",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4777b095",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:37.685209Z",
     "iopub.status.busy": "2026-08-14T20:58:37.685100Z",
     "iopub.status.idle": "2026-08-14T20:58:37.701532Z",
     "shell.execute_reply": "2026-08-14T20:58:37.701104Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Привет, друг!\n",
      "Привет, Ада!\n"
     ]
    }
   ],
   "source": [
    "def privetstvie(imya=\"друг\"):\n",
    "    print(f\"Привет, {imya}!\")\n",
    "\n",
    "privetstvie()\n",
    "privetstvie(\"Ада\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58c6ccaa",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — *args"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c5f2c456",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:37.702611Z",
     "iopub.status.busy": "2026-08-14T20:58:37.702499Z",
     "iopub.status.idle": "2026-08-14T20:58:37.705086Z",
     "shell.execute_reply": "2026-08-14T20:58:37.704693Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "15\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "def summa_vseh(*chisla):\n",
    "    itog = 0\n",
    "    for n in chisla:\n",
    "        itog += n\n",
    "    return itog\n",
    "\n",
    "print(summa_vseh(1, 2))\n",
    "print(summa_vseh(1, 2, 3, 4, 5))\n",
    "print(summa_vseh())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e011edc",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Напишите функцию `srednee(*chisla)`, которая возвращает среднее значение произвольного числа аргументов."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "68db1c27",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:37.706041Z",
     "iopub.status.busy": "2026-08-14T20:58:37.705939Z",
     "iopub.status.idle": "2026-08-14T20:58:37.708288Z",
     "shell.execute_reply": "2026-08-14T20:58:37.707914Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0\n",
      "25.0\n"
     ]
    }
   ],
   "source": [
    "def srednee(*chisla):\n",
    "    return sum(chisla) / len(chisla)\n",
    "\n",
    "print(srednee(1, 2, 3))\n",
    "print(srednee(10, 20, 30, 40))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af6d6286",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Именованные аргументы в любом порядке."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "81455d6f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:37.709438Z",
     "iopub.status.busy": "2026-08-14T20:58:37.709300Z",
     "iopub.status.idle": "2026-08-14T20:58:37.712081Z",
     "shell.execute_reply": "2026-08-14T20:58:37.711612Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cartesian, 30 лет\n"
     ]
    }
   ],
   "source": [
    "def opisat_cheloveka(imya, vozrast):\n",
    "    print(f\"{imya}, {vozrast} лет\")\n",
    "\n",
    "opisat_cheloveka(vozrast=30, imya=\"Cartesian\")  # порядок не важен с именами"
   ]
  }
 ],
 "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
}
