{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "homeless-zimbabwe",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=5  #promenljiva x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "horizontal-communist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "separated-variance",
   "metadata": {},
   "outputs": [],
   "source": [
    "y=\"zdravo svete\" #niska"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "killing-contest",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'zdravo svete'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "cardiac-minority",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1]   #lista sa jednim elementom koji je ceo broj\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "apparent-insight",
   "metadata": {},
   "outputs": [],
   "source": [
    "l=[\"Mika\", 10, \"Pera\", 20]    #lista sa vise elemenata razlicitog tipa. Prvi element ima indeks 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "weird-balloon",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Pera'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l[2]    # pristup elementu liste: promenljiva[indeks] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "inner-reminder",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(l)   # funkcija len vraca duzinu liste"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "coastal-amsterdam",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 'Pera']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "l[1:3]  # izdvajanje vise uzastopnih elemenata u listi  promenljiva[pocetak:kraj] \n",
    "        # Napomena:  izdvaja se elemenat sa indeksom pocetak, ali ne i element sa indeksom kraj, tj.  \n",
    "        # izdvajaju se elementi sa indeksima pocetak, pocetak+1, ..., kraj-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "supported-decade",
   "metadata": {},
   "outputs": [],
   "source": [
    "#kontrolne strukture\n",
    "# if iskaz, for iskaz, while iskaz"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "civilian-fourth",
   "metadata": {},
   "outputs": [],
   "source": [
    "# for promenljiva in lista:\n",
    "#    naredba\n",
    "#voditi racuna o udubljenju bloka u okviru petlje\n",
    "#udubljenje sa 4 ' ' z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "subject-necessity",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mika\n",
      "10\n",
      "Pera\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "for x in l:\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "focused-cosmetic",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "uslovi nisu zadovoljeni\n"
     ]
    }
   ],
   "source": [
    "#provera uslova sa if\n",
    "x=10   \n",
    "if x>10:\n",
    "    print('prvi uslov zadovoljen')\n",
    "elif x==5:\n",
    "    print('drugi uslov zadovoljen')\n",
    "else:\n",
    "    print('uslovi nisu zadovoljeni')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "confident-yesterday",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 ### uslovi nisu zadovoljeni\n",
      "15 prvi uslov zadovoljen\n",
      "2 ### uslovi nisu zadovoljeni\n",
      "5 drugi uslov zadovoljen\n"
     ]
    }
   ],
   "source": [
    "for x in [10, 15, 2, 5]:   \n",
    "    if x>10:\n",
    "        print(x, 'prvi uslov zadovoljen')\n",
    "    elif x==5:\n",
    "        print(x, 'drugi uslov zadovoljen')\n",
    "    else:\n",
    "        print(x, 'uslovi nisu zadovoljeni', sep=' ### ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "false-occasion",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i 0\n",
      "i 1\n",
      "i 2\n",
      "i 3\n",
      "i 4\n"
     ]
    }
   ],
   "source": [
    "i=0\n",
    "while i!=5:\n",
    "    print('i', i)\n",
    "    i+=1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "outstanding-france",
   "metadata": {},
   "outputs": [],
   "source": [
    "#ukljucivanje modula\n",
    "import math"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "antique-wallet",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "math.sqrt(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "governmental-house",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#ili sa uvodjenjem skracenice\n",
    "import math as m\n",
    "m.sqrt(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "rough-moscow",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#ili uvodjenjem samo zeljenih delova iz modula\n",
    "from math import sqrt\n",
    "sqrt(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "statistical-click",
   "metadata": {},
   "outputs": [],
   "source": [
    "#funkcije\n",
    "#def imefunkcije(arg1, arg2, ..., argn):\n",
    "#    naredbe\n",
    "#    return vrednost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "limiting-rates",
   "metadata": {},
   "outputs": [],
   "source": [
    "def sabiranje(x, y):\n",
    "    z=x+y\n",
    "    return z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "departmental-order",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sabiranje(5,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "joined-jenny",
   "metadata": {},
   "outputs": [],
   "source": [
    "def sabiranje(x, y):\n",
    "    return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "black-oxygen",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sabiranje(5,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "alternative-reason",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-03-04 23:54:16.198888\n",
      "2021\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(datetime.now())\n",
    "print(datetime.now().year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "demographic-produce",
   "metadata": {},
   "outputs": [],
   "source": [
    "#class ImeKlase:\n",
    "#    def __init__(self, arg1, arg2, ..., argN):\n",
    "#        self.atr1=arg1      #definisanje atributa koji mogu da se koriste\n",
    "#        self.atr2=arg2\n",
    "#        ...\n",
    "#        self.atrN=argN\n",
    "\n",
    "#     def metod1(self, arg1):   #self je uvek prvi arg i  predstavlja instancu koja ce pozvati metod \n",
    "#        ...\n",
    "\n",
    "#pravljenje instance klase ImeKlase\n",
    "#ime_inst=ImeKlase(arg1, arg2, ... , argN)\n",
    "#ime_inst.atr2  # vrednost atributa atr2 instance ime_inst\n",
    "#ime_inst.metod1(arg)  # pozivanje metoda metod1 za instancu ime_inst sa argumentom arg\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "missing-integrity",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Osoba:\n",
    "   \n",
    "    def __init__(self, ime_arg, godiste_arg):\n",
    "        self.ime=ime_arg\n",
    "        self.godiste=godiste_arg\n",
    "        \n",
    "    def ispisi_podatke(self):\n",
    "        print(self.ime, self.godiste)\n",
    "        \n",
    "    def broj_godina(self):\n",
    "        return datetime.now().year - self.godiste\n",
    "    \n",
    "    def __str__(self):\n",
    "        return '{0} ima {1} god'.format(self.ime, self.broj_godina())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "minimal-specialist",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pera 1980\n",
      "1980\n",
      "41\n",
      "Pera ima 41 god\n"
     ]
    }
   ],
   "source": [
    "pera=Osoba(\"Pera\", 1980)\n",
    "pera.ispisi_podatke()\n",
    "print(pera.godiste)\n",
    "print(pera.broj_godina())\n",
    "print(pera)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "cooked-contents",
   "metadata": {},
   "outputs": [],
   "source": [
    "#recnik cuva elemente u obliku kljuc:vrednost\n",
    "# odredjenoj vrednosti se pristupa sa recnik[kljuc]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "german-stylus",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a': 1, 'b': 2, 'c': 10}\n",
      "1\n",
      "{'a': 1, 'b': 2, 'c': 10, 'z': [1, 2, 3]}\n",
      "[1, 2, 3]\n"
     ]
    }
   ],
   "source": [
    "d={'a':1, 'b':2, 'c':10}\n",
    "print(d)  #ispis celog recnika\n",
    "print(d['a'])  #ispis vrednosti za kljuc a\n",
    "d['z']=[1,2,3] #dodavanje novog kljuca i njegove vrednosti\n",
    "print(d)\n",
    "print(d['z'])"
   ]
  }
 ],
 "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.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
