{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3c48412c",
   "metadata": {},
   "source": [
    "# 13-07 · Домашнее задание по математике\n",
    "\n",
    "Практика к разделу [«Мини-проект — домашнее задание по математике»](../../site/chapters/glava-13/13-07-mini-proekt-domashka.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b80c0786",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Функции, генерирующие и проверяющие примеры."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d607a3f3",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a02b6c8a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:40.150278Z",
     "iopub.status.busy": "2026-08-14T20:58:40.150164Z",
     "iopub.status.idle": "2026-08-14T20:58:40.165253Z",
     "shell.execute_reply": "2026-08-14T20:58:40.164788Z"
    }
   },
   "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": "89d54dc2",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8c43d564",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:40.166403Z",
     "iopub.status.busy": "2026-08-14T20:58:40.166283Z",
     "iopub.status.idle": "2026-08-14T20:58:40.169490Z",
     "shell.execute_reply": "2026-08-14T20:58:40.169018Z"
    }
   },
   "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": "42a99d0f",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — счётчик правильных ответов"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "07996b7c",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f60c788a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:40.170501Z",
     "iopub.status.busy": "2026-08-14T20:58:40.170391Z",
     "iopub.status.idle": "2026-08-14T20:58:40.172533Z",
     "shell.execute_reply": "2026-08-14T20:58:40.172179Z"
    }
   },
   "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": "a18efea9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:40.173572Z",
     "iopub.status.busy": "2026-08-14T20:58:40.173461Z",
     "iopub.status.idle": "2026-08-14T20:58:40.176663Z",
     "shell.execute_reply": "2026-08-14T20:58:40.176075Z"
    }
   },
   "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
}
