{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d67c2d16",
   "metadata": {},
   "source": [
    "# 16-28 · Таймер обратного отсчёта\n",
    "\n",
    "Практика к разделу [«Мини-проект: таймер обратного отсчёта»](../../site/chapters/glava-16/16-28-mini-proekt-tajmer.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e47320b2",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Проверить форматирование времени и логику одного тика таймера."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "47b99b25",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:24.157364Z",
     "iopub.status.busy": "2026-08-18T21:45:24.157257Z",
     "iopub.status.idle": "2026-08-18T21:45:24.180506Z",
     "shell.execute_reply": "2026-08-18T21:45:24.180042Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "01:05 10:00 00:05\n"
     ]
    }
   ],
   "source": [
    "def format_time(sekundy):\n",
    "    minuty, ostatok = divmod(sekundy, 60)\n",
    "    return f\"{minuty:02d}:{ostatok:02d}\"\n",
    "\n",
    "t1 = format_time(65)\n",
    "t2 = format_time(600)\n",
    "t3 = format_time(5)\n",
    "print(t1, t2, t3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11ed66fb",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача — тик с учётом running"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "db2fbf1e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:24.181628Z",
     "iopub.status.busy": "2026-08-18T21:45:24.181521Z",
     "iopub.status.idle": "2026-08-18T21:45:24.184136Z",
     "shell.execute_reply": "2026-08-18T21:45:24.183653Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 10\n"
     ]
    }
   ],
   "source": [
    "def tick(remaining, running):\n",
    "    if not running or remaining <= 0:\n",
    "        return remaining\n",
    "    return remaining - 1\n",
    "\n",
    "after_tick = tick(10, True)\n",
    "after_stop = tick(10, False)\n",
    "print(after_tick, after_stop)"
   ]
  }
 ],
 "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
}
