{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "887d137f",
   "metadata": {},
   "source": [
    "# 12-09 · Угадай число, версия 3\n",
    "\n",
    "Практика к разделу [«Проект: угадай число, версия 3»](../../site/chapters/glava-12/12-09-ugadaj-chislo-v3.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82571176",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Полная игра-угадайка: while, if/elif/else, счётчик попыток."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4aa7341e",
   "metadata": {},
   "source": [
    "## О случайности в этом ноутбуке\n",
    "\n",
    "Здесь секретное число зафиксировано (`secret = 37`), а не выбрано случайно — иначе автоматическая проверка результата была бы недетерминированной."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cb750b7",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8ae69c19",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:31.916986Z",
     "iopub.status.busy": "2026-08-17T16:38:31.916832Z",
     "iopub.status.idle": "2026-08-17T16:38:31.940786Z",
     "shell.execute_reply": "2026-08-17T16:38:31.940303Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['50', '25', '37'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1f29bab",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a2031694",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:31.942210Z",
     "iopub.status.busy": "2026-08-17T16:38:31.942079Z",
     "iopub.status.idle": "2026-08-17T16:38:31.944878Z",
     "shell.execute_reply": "2026-08-17T16:38:31.944415Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ваша попытка: 50\n",
      "Слишком много!\n",
      "Ваша попытка: 25\n",
      "Слишком мало!\n",
      "Ваша попытка: 37\n",
      "Поздравляем! Загадано было 37. Попыток: 3\n"
     ]
    }
   ],
   "source": [
    "secret = 37\n",
    "attempts = 0\n",
    "guess = None\n",
    "\n",
    "while guess != secret:\n",
    "    guess = int(input(\"Ваша попытка: \"))\n",
    "    attempts += 1\n",
    "    if guess < secret:\n",
    "        print(\"Слишком мало!\")\n",
    "    elif guess > secret:\n",
    "        print(\"Слишком много!\")\n",
    "    else:\n",
    "        print(f\"Поздравляем! Загадано было {secret}. Попыток: {attempts}\")"
   ]
  }
 ],
 "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
}
