{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "503a711d",
   "metadata": {},
   "source": [
    "# 13-22 · Рефакторинг викторины\n",
    "\n",
    "Практика к разделу [«Рефакторим проекты главы 12»](../../site/chapters/glava-13/13-22-refaktoring-glavy-12.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "316b4d6d",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Разбить викторину из главы 12 на функции check_answer и run_quiz."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2811b0db",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3b050171",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:54:14.915227Z",
     "iopub.status.busy": "2026-08-17T18:54:14.915126Z",
     "iopub.status.idle": "2026-08-17T18:54:14.933215Z",
     "shell.execute_reply": "2026-08-17T18:54:14.932476Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "def check_answer(user_answer, correct_answer):\n",
    "    return user_answer.strip().lower() == correct_answer.lower()\n",
    "\n",
    "def run_quiz(questions, answers):\n",
    "    score = 0\n",
    "    for q, given in zip(questions, answers):\n",
    "        if check_answer(given, q[\"answer\"]):\n",
    "            score += 1\n",
    "    return score\n",
    "\n",
    "questions = [{\"answer\": \"paris\"}, {\"answer\": \"56\"}]\n",
    "answers = [\"Paris\", \"56\"]\n",
    "final_score = run_quiz(questions, answers)\n",
    "print(final_score)"
   ]
  }
 ],
 "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
}
