{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Лекция 7. Часть 1 - практика на уроке\n",
    "\n",
    "Сниппеты для отработки на занятии. В каждой ячейке нужно либо:\n",
    "\n",
    "- заполнить пропуски `___`;\n",
    "- либо дописать код после комментария `# продолжите`.\n",
    "\n",
    "Заполните ячейку, запустите её и сравните вывод с ожидаемым результатом в комментарии `ожидается`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 1. Класс и экземпляр. Заполните пропуски ___\n",
    "class BankAccount:\n",
    "    def __init__(self, owner, balance):\n",
    "        self.owner = ___\n",
    "        self.balance = ___\n",
    "\n",
    "\n",
    "acc = BankAccount(\"Олег\", 7500)\n",
    "print(acc.owner, acc.balance)     # ожидается: Олег 7500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 1. Класс и экземпляр. Допишите метод __str__\n",
    "class BankAccount:\n",
    "    def __init__(self, owner, balance):\n",
    "        self.owner = owner\n",
    "        self.balance = balance\n",
    "\n",
    "    # продолжите\n",
    "\n",
    "\n",
    "print(BankAccount(\"Олег\", 7500))  # ожидается: Счёт Олег: 7500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 2. Наследование и super(). Заполните пропуски ___\n",
    "class BasicCard:\n",
    "    def __init__(self, holder, number):\n",
    "        self.holder = holder\n",
    "        self.number = number\n",
    "\n",
    "\n",
    "class PremiumCard(___):\n",
    "    def __init__(self, holder, number, cashback):\n",
    "        ___.__init__(holder, number)\n",
    "        self.cashback = cashback\n",
    "\n",
    "\n",
    "vip = PremiumCard(\"Asel\", \"8600...\", 0.05)\n",
    "print(vip.holder, vip.cashback)   # ожидается: Asel 0.05"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 2. Наследование. Допишите класс-наследник SavingsAccount\n",
    "class Account:\n",
    "    def __init__(self, owner):\n",
    "        self.owner = owner\n",
    "\n",
    "    def info(self):\n",
    "        print(\"Владелец:\", self.owner)\n",
    "\n",
    "\n",
    "# продолжите\n",
    "\n",
    "\n",
    "SavingsAccount(\"Олег\").info()     # ожидается: Владелец: Олег"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 3. Полиморфизм и super(). Заполните пропуск ___\n",
    "class PaymentGateway:\n",
    "    def process(self, amount):\n",
    "        print(\"Базовая обработка:\", amount)\n",
    "\n",
    "\n",
    "class UzCardGateway(PaymentGateway):\n",
    "    def process(self, amount):\n",
    "        ___.process(amount)\n",
    "        print(\"UzCard списывает:\", amount)\n",
    "\n",
    "\n",
    "UzCardGateway().process(150000)\n",
    "# ожидается:\n",
    "# Базовая обработка: 150000\n",
    "# UzCard списывает: 150000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 3. Полиморфизм. Допишите переопределение метода process\n",
    "class PaymentGateway:\n",
    "    def process(self, amount):\n",
    "        print(\"Базовая обработка:\", amount)\n",
    "\n",
    "\n",
    "class HumoGateway(PaymentGateway):\n",
    "    # продолжите\n",
    "    pass\n",
    "\n",
    "\n",
    "HumoGateway().process(50000)\n",
    "# ожидается:\n",
    "# Базовая обработка: 50000\n",
    "# Humo списывает: 50000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 4. Утиная типизация. Заполните пропуск ___\n",
    "class ApplePay:\n",
    "    def charge(self, amount):\n",
    "        print(\"Apple Pay:\", amount)\n",
    "\n",
    "\n",
    "def pay(service, amount):\n",
    "    service.___(amount)\n",
    "\n",
    "\n",
    "pay(ApplePay(), 50000)            # ожидается: Apple Pay: 50000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 4. Утиная типизация. Допишите класс GooglePay\n",
    "def pay(service, amount):\n",
    "    service.charge(amount)\n",
    "\n",
    "\n",
    "# продолжите\n",
    "\n",
    "\n",
    "pay(GooglePay(), 30000)           # ожидается: Google Pay: 30000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 5. MRO - порядок разрешения методов. Заполните пропуск ___\n",
    "class A:\n",
    "    pass\n",
    "\n",
    "\n",
    "class B(A):\n",
    "    pass\n",
    "\n",
    "\n",
    "print([c.__name__ for c in B.___])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 5. MRO. Предположите вывод, затем запустите и проверьте\n",
    "class Base:\n",
    "    def check(self): print(\"Base\")\n",
    "\n",
    "class Left(Base):\n",
    "    def check(self): print(\"Left\")\n",
    "\n",
    "class Right(Base):\n",
    "    def check(self): print(\"Right\")\n",
    "\n",
    "class Both(Left, Right):\n",
    "    pass\n",
    "\n",
    "\n",
    "Both().check()\n",
    "# почему сработал именно этот метод? ответ:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 6. Инкапсуляция. Заполните пропуски ___\n",
    "class User:\n",
    "    def __init__(self, role, pin):\n",
    "        self.___ = role\n",
    "        self.___ = pin\n",
    "\n",
    "\n",
    "u = User(\"client\", \"7721\")\n",
    "print(u._role)                    # ожидается: client\n",
    "print(u._User__pin)               # ожидается: 7721"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 6. Инкапсуляция. Допишите приватный атрибут и проверку доступа\n",
    "class Account:\n",
    "    def __init__(self, owner):\n",
    "        self.owner = owner\n",
    "        # продолжите: приватный атрибут баланса\n",
    "\n",
    "\n",
    "acc = Account(\"Олег\")\n",
    "# продолжите: обращение к acc.__balance в блоке try/except"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 7. @property. Заполните пропуск ___\n",
    "class Contract:\n",
    "    def __init__(self, number):\n",
    "        self._number = number\n",
    "\n",
    "    ___\n",
    "    def number(self):\n",
    "        return self._number\n",
    "\n",
    "\n",
    "print(Contract(\"UZ-001\").number)  # ожидается: UZ-001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 7. @property. Допишите сеттер, отклоняющий отрицательные значения\n",
    "class CreditLimit:\n",
    "    def __init__(self, limit):\n",
    "        self._limit = limit\n",
    "\n",
    "    @property\n",
    "    def limit(self):\n",
    "        return self._limit\n",
    "\n",
    "    # продолжите\n",
    "\n",
    "\n",
    "c = CreditLimit(500000)\n",
    "c.limit = 800000\n",
    "print(c.limit)                    # ожидается: 800000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 8. Атрибут класса. Заполните пропуск ___\n",
    "class Loan:\n",
    "    ___ = 0.20\n",
    "\n",
    "    def __init__(self, client):\n",
    "        self.client = client\n",
    "\n",
    "\n",
    "print(Loan(\"Тимур\").base_rate)    # ожидается: 0.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Тема 8. Атрибут класса. Допишите счётчик созданных объектов\n",
    "class Player:\n",
    "    count = 0\n",
    "\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "        # продолжите\n",
    "\n",
    "\n",
    "Player(\"A\")\n",
    "Player(\"B\")\n",
    "print(Player.count)               # ожидается: 2"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}