{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Punkt:\n",
    "    \"\"\"Reprezentacja punktu na płaszczyźnie.\n",
    "    \n",
    "    Atrybuty:\n",
    "        x (liczba): Wpółrzędna x-owa punktu.\n",
    "        y (liczba): Współrzędna y-owa punktu.\n",
    "        \n",
    "    Przykładowe wywołania i wartości zwracane:\n",
    "    \n",
    "    >>> str(Punkt(3.14, 22))\n",
    "    'Punkt (3.14,22)'\n",
    "    \n",
    "    >>> Punkt(\"ala\", 1)\n",
    "    Traceback (most recent call last):\n",
    "        ...\n",
    "    TypeError: Współrzędne punktu muszą być liczbami\n",
    "    \"\"\"\n",
    "    def __init__(self, x=0, y=0):\n",
    "        \"\"\" Konstruktor dla klasy Punkt\n",
    "        \n",
    "        Paramtery:\n",
    "            x (liczba): Wpółrzędna x-owa punktu.\n",
    "            y (liczba): Współrzędna y-owa punktu.\n",
    "        \"\"\"\n",
    "        if isinstance(x,str) or isinstance(y, str):\n",
    "            raise TypeError(\"Współrzędne punktu muszą być liczbami\")\n",
    "            \n",
    "        self.x = x\n",
    "        self.y = y\n",
    "    \n",
    "    def __add__(self, other):\n",
    "        \"\"\"Zwraca sumę dwóch punktów self i other\n",
    "        \n",
    "        >>> str(Punkt(1,2) + Punkt(-1,2.1))\n",
    "        'Punkt (0,4.1)'\n",
    "        \"\"\"\n",
    "        return Punkt(self.x+other.x, self.y+other.y)\n",
    "    \n",
    "    def __eq__(self, other):\n",
    "        return (self.x == other.x) and (self.y == other.y)\n",
    "    \n",
    "    def __str__(self):\n",
    "        return \"Punkt ({0},{1})\".format(self.x, self.y)\n",
    "    \n",
    "    def odległość(self):\n",
    "        \"\"\"Odległość punktu self od początku układu współrzędnych.\"\"\"\n",
    "        return (self.x**2 + self.y**2)**(1/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class Punkt in module __main__:\n",
      "\n",
      "class Punkt(builtins.object)\n",
      " |  Punkt(x=0, y=0)\n",
      " |  \n",
      " |  Reprezentacja punktu na płaszczyźnie.\n",
      " |  \n",
      " |  Atrybuty:\n",
      " |      x (liczba): Wpółrzędna x-owa punktu.\n",
      " |      y (liczba): Współrzędna y-owa punktu.\n",
      " |      \n",
      " |  Przykładowe wywołania i wartości zwracane:\n",
      " |  \n",
      " |  >>> str(Punkt(3.14, 22))\n",
      " |  'Punkt (3.14,22)'\n",
      " |  \n",
      " |  >>> Punkt(\"ala\", 1)\n",
      " |  Traceback (most recent call last):\n",
      " |      ...\n",
      " |  TypeError: Współrzędne punktu muszą być liczbami\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __add__(self, other)\n",
      " |      Zwraca sumę dwóch punktów\n",
      " |      \n",
      " |      >>> str(Punkt(1,2) + Punkt(-1,2.1))\n",
      " |      'Punkt (0,4.1)'\n",
      " |  \n",
      " |  __eq__(self, other)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __init__(self, x=0, y=0)\n",
      " |      Konstruktor dla klasy Punkt\n",
      " |      \n",
      " |      Paramtery:\n",
      " |          x (liczba): Wpółrzędna x-owa punktu.\n",
      " |          y (liczba): Współrzędna y-owa punktu.\n",
      " |  \n",
      " |  __str__(self)\n",
      " |      Return str(self).\n",
      " |  \n",
      " |  odległość(self)\n",
      " |      Odległość punktu self od początku układu współrzędnych.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  __dict__\n",
      " |      dictionary for instance variables (if defined)\n",
      " |  \n",
      " |  __weakref__\n",
      " |      list of weak references to the object (if defined)\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  __hash__ = None\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(Punkt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function odległość in module __main__:\n",
      "\n",
      "odległość(self)\n",
      "    Odległość punktu self od początku układu współrzędnych.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(Punkt.odległość)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Punkt (0,0)\n",
      "Punkt (1,2)\n",
      "Punkt (3,3)\n",
      "False\n",
      "2.23606797749979\n"
     ]
    }
   ],
   "source": [
    "p0 = Punkt()\n",
    "p1 = Punkt(1,2)\n",
    "p2 = Punkt(2,1)\n",
    "\n",
    "print(str(p0))\n",
    "print(str(p1))\n",
    "print(str(p1+p2))\n",
    "print(p1 == p2)\n",
    "print(p1.odległość())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exception reporting mode: Plain\n",
      "Doctest mode is: ON\n",
      "Exception reporting mode: Context\n",
      "Doctest mode is: OFF\n"
     ]
    }
   ],
   "source": [
    "%doctest_mode\n",
    "import doctest\n",
    "doctest.testmod()\n",
    "%doctest_mode"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
