{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6da7e93b",
   "metadata": {},
   "source": [
    "# 10-13 · Мини-проект «Цикл команд» и loop-else\n",
    "\n",
    "Практика к разделу [«break, continue и loop-else»](../../site/chapters/glava-10/10-04-break-continue.html#cikl-komand)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27533739",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Собрать while True + break из глав 8-9 в цикл команд, и закрепить loop-else."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7145a9c3",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, без живого человека за клавиатурой — поэтому здесь `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ed782cc1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:50.850182Z",
     "iopub.status.busy": "2026-08-16T20:12:50.850046Z",
     "iopub.status.idle": "2026-08-16T20:12:50.865361Z",
     "shell.execute_reply": "2026-08-16T20:12:50.864884Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['привет', 'list', 'stop'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "424e24c4",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика — цикл команд"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "50c55088",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:50.866438Z",
     "iopub.status.busy": "2026-08-16T20:12:50.866277Z",
     "iopub.status.idle": "2026-08-16T20:12:50.869021Z",
     "shell.execute_reply": "2026-08-16T20:12:50.868576Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Команда (help/list/stop): привет\n",
      "Добавлено в журнал: привет\n",
      "Команда (help/list/stop): list\n",
      "Журнал: ['привет']\n",
      "Команда (help/list/stop): stop\n",
      "Завершаю работу.\n"
     ]
    }
   ],
   "source": [
    "zhurnal = []\n",
    "while True:\n",
    "    komanda = input(\"Команда (help/list/stop): \").strip().lower()\n",
    "    if komanda == \"stop\":\n",
    "        print(\"Завершаю работу.\")\n",
    "        break\n",
    "    elif komanda == \"help\":\n",
    "        print(\"Доступно: help, list, stop\")\n",
    "    elif komanda == \"list\":\n",
    "        print(\"Журнал:\", zhurnal)\n",
    "    else:\n",
    "        zhurnal.append(komanda)\n",
    "        print(f\"Добавлено в журнал: {komanda}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1982dba",
   "metadata": {},
   "source": [
    "## Задание ★★ — loop-else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "081d41d7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:12:50.869907Z",
     "iopub.status.busy": "2026-08-16T20:12:50.869802Z",
     "iopub.status.idle": "2026-08-16T20:12:50.871977Z",
     "shell.execute_reply": "2026-08-16T20:12:50.871626Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "chisla = [4, 8, 15, 16, 23, 42]\n",
    "for n in chisla:\n",
    "    if n == 100:\n",
    "        naideno_100 = True\n",
    "        break\n",
    "else:\n",
    "    naideno_100 = False\n",
    "print(naideno_100)"
   ]
  }
 ],
 "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
}
