{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2cc3c5c0",
   "metadata": {},
   "source": [
    "# 12-01 · Чётное или нечётное\n",
    "\n",
    "Практика к разделу [«Проект 12-1»](../../site/chapters/glava-12/12-01-chetnoe-ili-nechetnoe.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6a837ee",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Закрепить условия и оператор %."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d1877c6",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "db443823",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:54.924617Z",
     "iopub.status.busy": "2026-08-14T20:55:54.924464Z",
     "iopub.status.idle": "2026-08-14T20:55:54.945457Z",
     "shell.execute_reply": "2026-08-14T20:55:54.944796Z"
    }
   },
   "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": "bd57eb81",
   "metadata": {},
   "source": [
    "## Часть 1 — одно число"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "43521657",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:54.946794Z",
     "iopub.status.busy": "2026-08-14T20:55:54.946638Z",
     "iopub.status.idle": "2026-08-14T20:55:54.949804Z",
     "shell.execute_reply": "2026-08-14T20:55:54.949030Z"
    }
   },
   "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": "5b11bc53",
   "metadata": {},
   "source": [
    "## Часть 2 — диапазон"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf87c03c",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "13d38096",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:54.951037Z",
     "iopub.status.busy": "2026-08-14T20:55:54.950871Z",
     "iopub.status.idle": "2026-08-14T20:55:54.953201Z",
     "shell.execute_reply": "2026-08-14T20:55:54.952716Z"
    }
   },
   "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": "fc8dc8aa",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:54.954210Z",
     "iopub.status.busy": "2026-08-14T20:55:54.954097Z",
     "iopub.status.idle": "2026-08-14T20:55:54.956557Z",
     "shell.execute_reply": "2026-08-14T20:55:54.956113Z"
    }
   },
   "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": "0363a5d4",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Выведите нечётные числа из того же диапазона."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "06224150",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:54.957451Z",
     "iopub.status.busy": "2026-08-14T20:55:54.957349Z",
     "iopub.status.idle": "2026-08-14T20:55:54.960158Z",
     "shell.execute_reply": "2026-08-14T20:55:54.959280Z"
    }
   },
   "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
}
