{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "172bc341",
   "metadata": {},
   "source": [
    "# 13-07 · Домашнее задание по математике\n",
    "\n",
    "Практика к разделу [«Мини-проект — домашнее задание по математике»](../../site/chapters/glava-13/13-07-mini-proekt-domashka.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8987d8ff",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Функции, генерирующие и проверяющие примеры."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e3a4e33",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9a44b83a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:47.617754Z",
     "iopub.status.busy": "2026-08-17T18:53:47.617614Z",
     "iopub.status.idle": "2026-08-17T18:53:47.636418Z",
     "shell.execute_reply": "2026-08-17T18:53:47.635998Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['42'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5765937",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "65156f4a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:47.637921Z",
     "iopub.status.busy": "2026-08-17T18:53:47.637770Z",
     "iopub.status.idle": "2026-08-17T18:53:47.640937Z",
     "shell.execute_reply": "2026-08-17T18:53:47.640497Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Пример: 4 x 3 = ? (правильный ответ: 12)\n",
      "Сколько будет 4 x 3? 42\n",
      "Неверно — правильный ответ: 12\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "random.seed(1)\n",
    "\n",
    "def sgenerirovat_primer():\n",
    "    a = random.randint(2, 9)\n",
    "    b = random.randint(2, 9)\n",
    "    return a, b, a * b\n",
    "\n",
    "def proverit_otvet(pravilnyj_otvet, otvet_polzovatelya):\n",
    "    return pravilnyj_otvet == otvet_polzovatelya\n",
    "\n",
    "a, b, pravilnyj_otvet = sgenerirovat_primer()\n",
    "print(f\"Пример: {a} x {b} = ? (правильный ответ: {pravilnyj_otvet})\")\n",
    "otvet = int(input(f\"Сколько будет {a} x {b}? \"))\n",
    "\n",
    "if proverit_otvet(pravilnyj_otvet, otvet):\n",
    "    print(\"Верно!\")\n",
    "else:\n",
    "    print(f\"Неверно — правильный ответ: {pravilnyj_otvet}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b56e3f42",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — счётчик правильных ответов"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23fe613c",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d8ab5851",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:47.641958Z",
     "iopub.status.busy": "2026-08-17T18:53:47.641755Z",
     "iopub.status.idle": "2026-08-17T18:53:47.643920Z",
     "shell.execute_reply": "2026-08-17T18:53:47.643556Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['1', '2', '3', '4', '5'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5c7f523d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:53:47.645019Z",
     "iopub.status.busy": "2026-08-17T18:53:47.644913Z",
     "iopub.status.idle": "2026-08-17T18:53:47.647870Z",
     "shell.execute_reply": "2026-08-17T18:53:47.647505Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Сколько будет 2 x 3? 1\n",
      "Сколько будет 3 x 7? 2\n",
      "Сколько будет 4 x 6? 3\n",
      "Сколько будет 6 x 5? 4\n",
      "Сколько будет 2 x 4? 5\n",
      "Правильных ответов: 0 из 5\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "random.seed(2)\n",
    "\n",
    "def sgenerirovat_primer():\n",
    "    a = random.randint(2, 9)\n",
    "    b = random.randint(2, 9)\n",
    "    return a, b, a * b\n",
    "\n",
    "pravilnyh = 0\n",
    "for _ in range(5):\n",
    "    a, b, pravilnyj_otvet = sgenerirovat_primer()\n",
    "    otvet = int(input(f\"Сколько будет {a} x {b}? \"))\n",
    "    if otvet == pravilnyj_otvet:\n",
    "        pravilnyh += 1\n",
    "\n",
    "print(f\"Правильных ответов: {pravilnyh} из 5\")"
   ]
  }
 ],
 "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
}
