{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7ff4bbf1",
   "metadata": {},
   "source": [
    "# 13-04 · Аргументы функций\n",
    "\n",
    "Практика к разделу [«Нет аргументов? Слишком много аргументов!»](../../site/chapters/glava-13/13-04-argumenty.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "610b3c36",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить значения по умолчанию и *args."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b515028f",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "321fffd4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:41.761955Z",
     "iopub.status.busy": "2026-08-17T18:53:41.761839Z",
     "iopub.status.idle": "2026-08-17T18:53:41.780836Z",
     "shell.execute_reply": "2026-08-17T18:53:41.780382Z"
    }
   },
   "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": "545e86e9",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — *args"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6705d686",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:41.781911Z",
     "iopub.status.busy": "2026-08-17T18:53:41.781796Z",
     "iopub.status.idle": "2026-08-17T18:53:41.784414Z",
     "shell.execute_reply": "2026-08-17T18:53:41.783981Z"
    }
   },
   "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": "ecc98243",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Напишите функцию `srednee(*chisla)`, которая возвращает среднее значение произвольного числа аргументов."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "807ad081",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:41.785392Z",
     "iopub.status.busy": "2026-08-17T18:53:41.785283Z",
     "iopub.status.idle": "2026-08-17T18:53:41.787671Z",
     "shell.execute_reply": "2026-08-17T18:53:41.787191Z"
    }
   },
   "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": "6697f982",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Именованные аргументы в любом порядке."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "08396970",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:41.788552Z",
     "iopub.status.busy": "2026-08-17T18:53:41.788438Z",
     "iopub.status.idle": "2026-08-17T18:53:41.790907Z",
     "shell.execute_reply": "2026-08-17T18:53:41.790425Z"
    }
   },
   "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
}
