{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6f06a2d5",
   "metadata": {},
   "source": [
    "# 10-22 · Сентинел-цикл\n",
    "\n",
    "Практика к разделу [«Поиск, фильтрация и суммирование»](../../site/chapters/glava-10/10-11-poisk-filtr-summa.html#sentinel)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5e8c930",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Освоить сентинел-цикл — особое значение как сигнал остановки."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b4a879be",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, без живого человека за клавиатурой — поэтому здесь `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "97f5b113",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:55.646985Z",
     "iopub.status.busy": "2026-08-16T20:12:55.646873Z",
     "iopub.status.idle": "2026-08-16T20:12:55.677488Z",
     "shell.execute_reply": "2026-08-16T20:12:55.676959Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['5', '10', 'stop'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b46c7c06",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c7135d76",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:55.678507Z",
     "iopub.status.busy": "2026-08-16T20:12:55.678380Z",
     "iopub.status.idle": "2026-08-16T20:12:55.681049Z",
     "shell.execute_reply": "2026-08-16T20:12:55.680563Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Введите число (stop — закончить): 5\n",
      "Введите число (stop — закончить): 10\n",
      "Введите число (stop — закончить): stop\n",
      "Сумма: 15\n"
     ]
    }
   ],
   "source": [
    "summa = 0\n",
    "while True:\n",
    "    chislo = input(\"Введите число (stop — закончить): \")\n",
    "    if chislo == \"stop\":\n",
    "        break\n",
    "    summa += int(chislo)\n",
    "print(\"Сумма:\", summa)"
   ]
  }
 ],
 "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
}
