{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "353881f7",
   "metadata": {},
   "source": [
    "# 12-02 · Достаточно ли чаевых?\n",
    "\n",
    "Практика к разделу [«Проект 12-2»](../../site/chapters/glava-12/12-02-chaevye.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1edb862c",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Закрепить арифметику, форматирование и elif."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5101d01d",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "64919559",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:55.755930Z",
     "iopub.status.busy": "2026-08-14T20:55:55.755809Z",
     "iopub.status.idle": "2026-08-14T20:55:55.777529Z",
     "shell.execute_reply": "2026-08-14T20:55:55.777005Z"
    }
   },
   "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": "176c3d5c",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "340193bd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:55.778855Z",
     "iopub.status.busy": "2026-08-14T20:55:55.778713Z",
     "iopub.status.idle": "2026-08-14T20:55:55.781523Z",
     "shell.execute_reply": "2026-08-14T20:55:55.781105Z"
    }
   },
   "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": "5e8d4ce2",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Добавьте категорию «сказочно щедро» для чаевых больше 30%."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d62cd893",
   "metadata": {},
   "source": [
    "## Про input() в этом ноутбуке\n",
    "\n",
    "Этот ноутбук выполняется автоматически, поэтому `input()` временно подменён на заранее заготовленные ответы."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "81178ceb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:55.782608Z",
     "iopub.status.busy": "2026-08-14T20:55:55.782498Z",
     "iopub.status.idle": "2026-08-14T20:55:55.784886Z",
     "shell.execute_reply": "2026-08-14T20:55:55.784171Z"
    }
   },
   "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": "46655a7d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:55.785842Z",
     "iopub.status.busy": "2026-08-14T20:55:55.785733Z",
     "iopub.status.idle": "2026-08-14T20:55:55.789568Z",
     "shell.execute_reply": "2026-08-14T20:55:55.788896Z"
    }
   },
   "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
}
