{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2367da11",
   "metadata": {},
   "source": [
    "# 10-02 · if внутри циклов, вложенные циклы\n",
    "\n",
    "Практика к разделу [«Условия if внутри циклов for»](../../site/chapters/glava-10/10-02-if-vlozhennye-cikly.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70999017",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Сочетать if с for и вкладывать циклы друг в друга."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1dd03f28",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d8482ee9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:58.145910Z",
     "iopub.status.busy": "2026-08-14T20:53:58.145765Z",
     "iopub.status.idle": "2026-08-14T20:53:58.166010Z",
     "shell.execute_reply": "2026-08-14T20:53:58.165497Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 — чётное\n",
      "4 — чётное\n",
      "6 — чётное\n",
      "8 — чётное\n",
      "10 — чётное\n"
     ]
    }
   ],
   "source": [
    "for number in range(1, 11):\n",
    "    if number % 2 == 0:\n",
    "        print(number, \"— чётное\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6d6fad7",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — вложенные циклы"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "abc67c8e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:58.167033Z",
     "iopub.status.busy": "2026-08-14T20:53:58.166914Z",
     "iopub.status.idle": "2026-08-14T20:53:58.169379Z",
     "shell.execute_reply": "2026-08-14T20:53:58.169051Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 0) (0, 1) (0, 2) (0, 3) \n",
      "(1, 0) (1, 1) (1, 2) (1, 3) \n",
      "(2, 0) (2, 1) (2, 2) (2, 3) \n"
     ]
    }
   ],
   "source": [
    "for row in range(3):\n",
    "    for col in range(4):\n",
    "        print(f\"({row}, {col})\", end=\" \")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be5b101c",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Выведите треугольник из звёздочек: 1 звезда в первой строке, 2 во второй, ..., 5 в пятой."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5deb820c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:58.170491Z",
     "iopub.status.busy": "2026-08-14T20:53:58.170388Z",
     "iopub.status.idle": "2026-08-14T20:53:58.172694Z",
     "shell.execute_reply": "2026-08-14T20:53:58.172267Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*\n",
      "**\n",
      "***\n",
      "****\n",
      "*****\n"
     ]
    }
   ],
   "source": [
    "for row in range(1, 6):\n",
    "    print(\"*\" * row)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a56e6134",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Выведите таблицу умножения 1-5 x 1-5 вложенными циклами."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "532175d9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:58.173554Z",
     "iopub.status.busy": "2026-08-14T20:53:58.173457Z",
     "iopub.status.idle": "2026-08-14T20:53:58.176098Z",
     "shell.execute_reply": "2026-08-14T20:53:58.175468Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  1   2   3   4   5 \n",
      "  2   4   6   8  10 \n",
      "  3   6   9  12  15 \n",
      "  4   8  12  16  20 \n",
      "  5  10  15  20  25 \n"
     ]
    }
   ],
   "source": [
    "for a in range(1, 6):\n",
    "    for b in range(1, 6):\n",
    "        print(f\"{a * b:3}\", end=\" \")\n",
    "    print()"
   ]
  }
 ],
 "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
}
