{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cbee6759",
   "metadata": {},
   "source": [
    "# 14-22 · Praktyka: __str__ i __eq__\n",
    "\n",
    "Praktyka do sekcji [„Praktyka: zastosować __str__ i __eq__”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2df5192a",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Zastosować __str__ i __eq__ do klasy Tochka."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0f16009",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f6e20d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Tochka:\n",
    "    def __init__(self, x, y):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"({self.x}, {self.y})\"\n",
    "\n",
    "    def __eq__(self, other):\n",
    "        return self.x == other.x and self.y == other.y\n",
    "\n",
    "a = Tochka(1, 2)\n",
    "b = Tochka(1, 2)\n",
    "c = Tochka(5, 5)\n",
    "print(str(a), a == b, a == c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "043f38c3",
   "metadata": {},
   "source": [
    "## Zadanie niezależne od zadania ★★\n",
    "\n",
    "Dodaj `Tochka` metoda `rasstoyanie_do(other)`który zwraca dystans euklidesowy do innego punktu."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d432ae09",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Tochka:\n",
    "    def __init__(self, x, y):\n",
    "        self.x = x\n",
    "        self.y = y\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"({self.x}, {self.y})\"\n",
    "\n",
    "    def __eq__(self, other):\n",
    "        return self.x == other.x and self.y == other.y\n",
    "\n",
    "    def rasstoyanie_do(self, other):\n",
    "        return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5\n",
    "\n",
    "nachalo = Tochka(0, 0)\n",
    "konec = Tochka(3, 4)\n",
    "rasstoyanie = nachalo.rasstoyanie_do(konec)\n",
    "print(rasstoyanie)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "name": "python",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
