{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9ab56276",
   "metadata": {},
   "source": [
    "# 16-24 · Архитектура приложения\n",
    "\n",
    "Практика к разделу [«Архитектура приложения: логика отдельно от виджетов»](../../site/chapters/glava-16/16-24-arhitektura-prilozheniya.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e20c4078",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Проверить чистую доменную функцию и исправить ловушку lambda в цикле."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "14dbb507",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:20.955600Z",
     "iopub.status.busy": "2026-08-18T21:45:20.955472Z",
     "iopub.status.idle": "2026-08-18T21:45:20.976153Z",
     "shell.execute_reply": "2026-08-18T21:45:20.975731Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "75.0\n"
     ]
    }
   ],
   "source": [
    "def calculate_tip(amount, percent, people):\n",
    "    total_tip = amount * percent / 100\n",
    "    return total_tip / people\n",
    "\n",
    "result = calculate_tip(1000, 15, 2)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6d1c2dc",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — позднее связывание в lambda"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4e6d6ee3",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:20.977318Z",
     "iopub.status.busy": "2026-08-18T21:45:20.977211Z",
     "iopub.status.idle": "2026-08-18T21:45:20.979889Z",
     "shell.execute_reply": "2026-08-18T21:45:20.979420Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2]\n"
     ]
    }
   ],
   "source": [
    "callbacks = []\n",
    "for i in range(3):\n",
    "    callbacks.append(lambda i=i: i)\n",
    "\n",
    "values = [cb() for cb in callbacks]\n",
    "print(values)"
   ]
  }
 ],
 "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
}
