{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e22d727f",
   "metadata": {},
   "source": [
    "# 12-01 · Чётное или нечётное\n",
    "\n",
    "Практика к разделу [«Проект 12-1»](../../site/chapters/glava-12/12-01-chetnoe-ili-nechetnoe.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "369b01ab",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Закрепить условия и оператор %."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a88de840",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "72380d75",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:24.207308Z",
     "iopub.status.busy": "2026-08-17T16:38:24.207133Z",
     "iopub.status.idle": "2026-08-17T16:38:24.224575Z",
     "shell.execute_reply": "2026-08-17T16:38:24.224118Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['17'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3631dcd",
   "metadata": {},
   "source": [
    "## Часть 1 — одно число"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f54030fd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:24.225898Z",
     "iopub.status.busy": "2026-08-17T16:38:24.225784Z",
     "iopub.status.idle": "2026-08-17T16:38:24.228321Z",
     "shell.execute_reply": "2026-08-17T16:38:24.227819Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Введите число: 17\n",
      "17 — нечётное.\n"
     ]
    }
   ],
   "source": [
    "number = int(input(\"Введите число: \"))\n",
    "if number % 2 == 0:\n",
    "    print(f\"{number} — чётное.\")\n",
    "else:\n",
    "    print(f\"{number} — нечётное.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e6aacbd",
   "metadata": {},
   "source": [
    "## Часть 2 — диапазон"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21100582",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "93be6b34",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:24.229555Z",
     "iopub.status.busy": "2026-08-17T16:38:24.229443Z",
     "iopub.status.idle": "2026-08-17T16:38:24.231569Z",
     "shell.execute_reply": "2026-08-17T16:38:24.231132Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['1', '20'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "966d667a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:24.232449Z",
     "iopub.status.busy": "2026-08-17T16:38:24.232343Z",
     "iopub.status.idle": "2026-08-17T16:38:24.234808Z",
     "shell.execute_reply": "2026-08-17T16:38:24.234446Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Начало диапазона: 1\n",
      "Конец диапазона: 20\n",
      "Чётные числа: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n"
     ]
    }
   ],
   "source": [
    "nachalo = int(input(\"Начало диапазона: \"))\n",
    "konec = int(input(\"Конец диапазона: \"))\n",
    "\n",
    "chetnye = [n for n in range(nachalo, konec + 1) if n % 2 == 0]\n",
    "print(\"Чётные числа:\", chetnye)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50b4393d",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Выведите нечётные числа из того же диапазона."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d9ece01a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:24.235850Z",
     "iopub.status.busy": "2026-08-17T16:38:24.235742Z",
     "iopub.status.idle": "2026-08-17T16:38:24.238097Z",
     "shell.execute_reply": "2026-08-17T16:38:24.237760Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Нечётные числа: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]\n"
     ]
    }
   ],
   "source": [
    "nachalo, konec = 1, 20\n",
    "nechetnye = [n for n in range(nachalo, konec + 1) if n % 2 != 0]\n",
    "print(\"Нечётные числа:\", nechetnye)"
   ]
  }
 ],
 "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
}
