{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "51a69cc6",
   "metadata": {},
   "source": [
    "# 12-10 · Угадай число — ограничение попыток\n",
    "\n",
    "Практика к разделу [«Проект: угадай число, версия 3»](../../site/chapters/glava-12/12-09-ugadaj-chislo-v3.html#uroven-3)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a554487",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Уровень 3: игра заканчивается поражением после ограниченного числа попыток."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f4321b1",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d20d8487",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:33.848393Z",
     "iopub.status.busy": "2026-08-17T16:38:33.848237Z",
     "iopub.status.idle": "2026-08-17T16:38:33.860937Z",
     "shell.execute_reply": "2026-08-17T16:38:33.860496Z"
    }
   },
   "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": "1ab44b34",
   "metadata": {},
   "source": [
    "## Задание ★★★ Задача повышенной сложности"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c5fb5ef4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:33.862212Z",
     "iopub.status.busy": "2026-08-17T16:38:33.862094Z",
     "iopub.status.idle": "2026-08-17T16:38:33.865099Z",
     "shell.execute_reply": "2026-08-17T16:38:33.864666Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ваша попытка: 50\n",
      "Слишком много!\n",
      "Ваша попытка: 25\n",
      "Слишком мало!\n",
      "Ваша попытка: 37\n",
      "Победа за 3 попыток!\n"
     ]
    }
   ],
   "source": [
    "secret = 37\n",
    "max_attempts = 5\n",
    "attempts = 0\n",
    "guess = None\n",
    "\n",
    "while guess != secret and attempts < max_attempts:\n",
    "    guess = int(input(\"Ваша попытка: \"))\n",
    "    attempts += 1\n",
    "    if guess < secret:\n",
    "        print(\"Слишком мало!\")\n",
    "    elif guess > secret:\n",
    "        print(\"Слишком много!\")\n",
    "\n",
    "if guess == secret:\n",
    "    print(f\"Победа за {attempts} попыток!\")\n",
    "    pobeda = True\n",
    "else:\n",
    "    print(f\"Числа закончились. Было загадано {secret}.\")\n",
    "    pobeda = False"
   ]
  }
 ],
 "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
}
