{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ccf29c0f",
   "metadata": {},
   "source": [
    "# 12-02 · Достаточно ли чаевых?\n",
    "\n",
    "Практика к разделу [«Проект 12-2»](../../site/chapters/glava-12/12-02-chaevye.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5930936",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Закрепить арифметику, форматирование и elif."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42f3f97e",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "30bdcd92",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:26.124150Z",
     "iopub.status.busy": "2026-08-17T16:38:26.124040Z",
     "iopub.status.idle": "2026-08-17T16:38:26.148403Z",
     "shell.execute_reply": "2026-08-17T16:38:26.148030Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['1000', '150'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf724424",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0f81048b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:26.149817Z",
     "iopub.status.busy": "2026-08-17T16:38:26.149699Z",
     "iopub.status.idle": "2026-08-17T16:38:26.152430Z",
     "shell.execute_reply": "2026-08-17T16:38:26.152045Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Сумма счёта: 1000\n",
      "Сумма чаевых: 150\n",
      "В самый раз — 15.0%!\n"
     ]
    }
   ],
   "source": [
    "schet = float(input(\"Сумма счёта: \"))\n",
    "chaevye = float(input(\"Сумма чаевых: \"))\n",
    "\n",
    "procent = (chaevye / schet) * 100\n",
    "\n",
    "if procent < 15:\n",
    "    print(f\"Маловато — всего {procent:.1f}%. Обычно оставляют 15-20%.\")\n",
    "elif procent <= 20:\n",
    "    print(f\"В самый раз — {procent:.1f}%!\")\n",
    "else:\n",
    "    print(f\"Очень щедро — целых {procent:.1f}%!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5ffad951",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Добавьте категорию «сказочно щедро» для чаевых больше 30%."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f644971",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ee05db62",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:26.153356Z",
     "iopub.status.busy": "2026-08-17T16:38:26.153253Z",
     "iopub.status.idle": "2026-08-17T16:38:26.155376Z",
     "shell.execute_reply": "2026-08-17T16:38:26.154935Z"
    }
   },
   "outputs": [],
   "source": [
    "_answers = iter(['1000', '350'])\n",
    "\n",
    "def input(prompt=\"\"):\n",
    "    answer = next(_answers)\n",
    "    print(prompt + answer)\n",
    "    return answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a7156b42",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:38:26.156281Z",
     "iopub.status.busy": "2026-08-17T16:38:26.156178Z",
     "iopub.status.idle": "2026-08-17T16:38:26.158851Z",
     "shell.execute_reply": "2026-08-17T16:38:26.158439Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Сумма счёта: 1000\n",
      "Сумма чаевых: 350\n",
      "Сказочно щедро — 35.0%!\n"
     ]
    }
   ],
   "source": [
    "schet = float(input(\"Сумма счёта: \"))\n",
    "chaevye = float(input(\"Сумма чаевых: \"))\n",
    "procent = (chaevye / schet) * 100\n",
    "\n",
    "if procent < 15:\n",
    "    print(f\"Маловато — всего {procent:.1f}%.\")\n",
    "elif procent <= 20:\n",
    "    print(f\"В самый раз — {procent:.1f}%!\")\n",
    "elif procent <= 30:\n",
    "    print(f\"Очень щедро — целых {procent:.1f}%!\")\n",
    "else:\n",
    "    print(f\"Сказочно щедро — {procent:.1f}%!\")"
   ]
  }
 ],
 "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
}
