{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5e59ad0b",
   "metadata": {},
   "source": [
    "# 09-04 · and, or, not\n",
    "\n",
    "Практика к разделу [«Больше одного условия!»](../../site/chapters/glava-09/09-04-neskolko-uslovij.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abc3c1b7",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Комбинировать условия логическими операторами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fcfa2527",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5dd924fd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.938327Z",
     "iopub.status.busy": "2026-08-14T20:53:54.938218Z",
     "iopub.status.idle": "2026-08-14T20:53:54.957380Z",
     "shell.execute_reply": "2026-08-14T20:53:54.956992Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Проходите в зал.\n"
     ]
    }
   ],
   "source": [
    "age = 20\n",
    "has_ticket = True\n",
    "if age >= 18 and has_ticket:\n",
    "    print(\"Проходите в зал.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c6676c3",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — or"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "49cb6366",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.958709Z",
     "iopub.status.busy": "2026-08-14T20:53:54.958584Z",
     "iopub.status.idle": "2026-08-14T20:53:54.961817Z",
     "shell.execute_reply": "2026-08-14T20:53:54.961321Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Сегодня можно не ходить на работу.\n"
     ]
    }
   ],
   "source": [
    "is_weekend = False\n",
    "is_holiday = True\n",
    "if is_weekend or is_holiday:\n",
    "    print(\"Сегодня можно не ходить на работу.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12572d04",
   "metadata": {},
   "source": [
    "## Эксперимент 2 — таблица истинности"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "81ab4381",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.962953Z",
     "iopub.status.busy": "2026-08-14T20:53:54.962818Z",
     "iopub.status.idle": "2026-08-14T20:53:54.965444Z",
     "shell.execute_reply": "2026-08-14T20:53:54.964992Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True and True = True  |  True or True = True\n",
      "True and False = False  |  True or False = True\n",
      "False and True = False  |  False or True = True\n",
      "False and False = False  |  False or False = False\n"
     ]
    }
   ],
   "source": [
    "for a in [True, False]:\n",
    "    for b in [True, False]:\n",
    "        print(a, \"and\", b, \"=\", a and b, \" | \", a, \"or\", b, \"=\", a or b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c92f2e6",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Проверьте, подходит ли кандидат: возраст от 18 до 65 включительно (два условия через and)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9194cb25",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.966371Z",
     "iopub.status.busy": "2026-08-14T20:53:54.966267Z",
     "iopub.status.idle": "2026-08-14T20:53:54.968627Z",
     "shell.execute_reply": "2026-08-14T20:53:54.968217Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Подходит по возрасту.\n"
     ]
    }
   ],
   "source": [
    "age = 30\n",
    "if age >= 18 and age <= 65:\n",
    "    print(\"Подходит по возрасту.\")\n",
    "else:\n",
    "    print(\"Не подходит по возрасту.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffd55950",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "То же самое, но через сцепленное сравнение Python `18 <= age <= 65` — более короткая и «питоничная» форма того же условия."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "27ee1fca",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:53:54.969600Z",
     "iopub.status.busy": "2026-08-14T20:53:54.969497Z",
     "iopub.status.idle": "2026-08-14T20:53:54.971663Z",
     "shell.execute_reply": "2026-08-14T20:53:54.971293Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Подходит по возрасту (сцепленное сравнение).\n"
     ]
    }
   ],
   "source": [
    "age = 30\n",
    "if 18 <= age <= 65:\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
}
