{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "79908dc6",
   "metadata": {},
   "source": [
    "# How Jupyter works"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "408602ca",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'x' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn [1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mx\u001b[49m)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'x' is not defined"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "598f5bed",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77d75f52",
   "metadata": {},
   "source": [
    "## Basic commands\n",
    "\n",
    "Jupyter Notebook is widely used for data analysis. The notebooks documents are documents produced by the Jupyter Notebook App, which can contain both code (e.g. Python) and rich text elements (paragraphs, equations, links, etc.).\n",
    "\n",
    "The Jupyter Notebook App is a client-server application that allows editing and running notebook documents by a browser.\n",
    "\n",
    "### Shortcuts in both modes:\n",
    "- Shift + Enter run the current cell, select below\n",
    "- Ctrl + Enter run selected cells\n",
    "- Alt + Enter run the current cell, insert below\n",
    "- Ctrl + S save and checkpoint"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aea23ddf",
   "metadata": {},
   "source": [
    "### While in command mode (press Esc to activate):\n",
    "\n",
    "**Enter take you into edit mode** and also **considers that some commands en Google collab have been modified and require first the `Ctr+M` command** and then the command that you need like change the cell type to Markdown:\n",
    "\n",
    "- H show all shortcuts `Ctr+M`\n",
    "- Up select cell above\n",
    "- Down select cell below\n",
    "- Shift + Up extend selected cells above\n",
    "- Shift + Down extend selected cells below\n",
    "- A insert cell above\n",
    "- B insert cell below\n",
    "- X cut selected cells\n",
    "- C copy selected cells\n",
    "- V paste cells below\n",
    "- Shift + V paste cells above\n",
    "- D, D (press the key twice) delete selected cells `Ctr+M`\n",
    "- Z undo cell deletion\n",
    "- S Save and Checkpoint `Ctr+M`\n",
    "- Y change the cell type to Code `Ctr+M` \n",
    "- M change the cell type to Markdown `Ctr+M`\n",
    "- P open the command palette `Ctr+M`\n",
    "\n",
    "This dialog helps you run any command by name. It’s really useful if you don’t know some shortcut or when you don’t have a shortcut for the wanted command.\n",
    "\n",
    "- Shift + Space scroll notebook up\n",
    "- Space scroll notebook down"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6066c3fc",
   "metadata": {},
   "source": [
    "### While in edit mode (press Enter to activate)\n",
    "- Esc take you into command mode\n",
    "- Tab code completion or indent\n",
    "- Shift + Tab tooltip\n",
    "- Ctrl + ] indent\n",
    "- Ctrl + [ dedent\n",
    "- Ctrl + A select all\n",
    "- Ctrl + Z undo\n",
    "- Ctrl + Shift + Z or Ctrl + Y redo\n",
    "- Ctrl + Home go to cell start\n",
    "- Ctrl + End go to cell end\n",
    "- Ctrl + Left go one word left\n",
    "- Ctrl + Right go one word right\n",
    "- Ctrl + Shift + P open the command palette\n",
    "- Down move cursor down\n",
    "- Up move cursor up"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dad4c1fb",
   "metadata": {},
   "source": [
    "# Basics of Python and Programming\n",
    "## Using conditionals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9272c3fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "El valor es positivo\n"
     ]
    }
   ],
   "source": [
    "x = 1 #int(input('Introduce un numero: '))\n",
    "if x<0:\n",
    "    print('El valor es negativo')\n",
    "else:\n",
    "    print(\"El valor es positivo\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "90916e74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Introduce un numero: -5\n",
      "El valor es negativo\n"
     ]
    }
   ],
   "source": [
    "x = int(input('Introduce un numero: '))\n",
    "if x<0:\n",
    "    print('El valor es negativo')\n",
    "else:\n",
    "    print(\"El valor es positivo\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e246b55e",
   "metadata": {},
   "source": [
    "## Using for loops"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7d68db25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "juan\n",
      "israel\n",
      "jonathan\n",
      "homero\n"
     ]
    }
   ],
   "source": [
    "nombres = ['juan', 'israel', 'jonathan', 'homero']\n",
    "for n in nombres:\n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b5a09022",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "for n in range(1,11):\n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e163a7e0",
   "metadata": {},
   "source": [
    "## Arrays and indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d98ef5bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "a = np.array([[1,2],[3,4],[5,6]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "096d51b8",
   "metadata": {},
   "source": [
    "## Functions "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fd363297",
   "metadata": {},
   "outputs": [],
   "source": [
    "# how to crate functions\n",
    "def myFuncion(x):\n",
    "    y = np.sin(x)/np.cos(x)\n",
    "    return y"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8fada9a",
   "metadata": {},
   "source": [
    "## Making basic plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b956d7c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 36040 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "time = np.linspace(0,10)\n",
    "y = myFuncion(time)\n",
    "y2 = np.tan(time)\n",
    "plt.plot(time, y/2,'-g*')\n",
    "plt.plot(time, y2, ':m+')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "280bf852",
   "metadata": {},
   "source": [
    "### Subplot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "048067ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 40824 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 3 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.subplot(3,1,1)\n",
    "plt.plot(time, np.sin(time),'r', label='$y_1$')\n",
    "plt.legend()\n",
    "plt.subplot(3,1,2)\n",
    "plt.plot(time, np.cos(time),'g',label='y2')\n",
    "plt.legend()\n",
    "plt.subplot(3,1,3)\n",
    "plt.plot(time, np.tan(time),'k', label='y3')\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "4be8971b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 27056 characters]\n",
      "text/plain": [
       "<Figure size 640x480 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.subplot(6,3,1)\n",
    "plt.plot(time, np.sin(time),'r', label='y_1')\n",
    "plt.subplot(6,3,2)\n",
    "plt.plot(time, np.cos(time),'g',label='y2')\n",
    "plt.subplot(6,3,3)\n",
    "plt.plot(time, np.tan(time),'k', label='y3')\n",
    "plt.subplot(6,3,4)\n",
    "plt.plot(time, np.sin(time),'r', label='$y_1$')\n",
    "plt.subplot(6,3,5)\n",
    "plt.plot(time, np.cos(time),'g',label='y2')\n",
    "plt.subplot(6,3,6)\n",
    "plt.plot(time, np.tan(time),'k', label='$y_1$')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8236e97a",
   "metadata": {},
   "source": [
    "# Some additions task and work"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "937e9070",
   "metadata": {},
   "source": [
    "- Make function that computes the factorial of a given numer using for loops\n",
    "- Make a function that computes 4 functions (sin, cos, tan, logistic) and plots \n",
    "- Make a function that recive your age and classifies you as baby, teenager, ...."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f60bf212",
   "metadata": {},
   "source": [
    "## factorial"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2eee578a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def factorial(argument):\n",
    "    mul=1\n",
    "    for n in range(1,argument):\n",
    "        prod = mul*(n+1)\n",
    "        mul = prod\n",
    "        print(prod)\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9c9addfe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "6\n",
      "24\n",
      "120\n",
      "720\n",
      "5040\n"
     ]
    }
   ],
   "source": [
    "factorial(7)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "841a2854",
   "metadata": {},
   "source": [
    "## making plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d19216c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "def myPlots(x):\n",
    "    y1 = np.sin(x)\n",
    "    y2 = np.cos(x)\n",
    "    y3 = np.tan(x)\n",
    "    y4 = 1/(1+np.exp(-x))\n",
    "    #plots\n",
    "    plt.figure(figsize=(10,10))\n",
    "    plt.subplot(4,4,1)\n",
    "    plt.plot(x, y1)\n",
    "    plt.subplot(4,4,2)\n",
    "    plt.plot(x, y2)\n",
    "    plt.subplot(4,4,3)\n",
    "    plt.plot(x, y3)\n",
    "    plt.subplot(4,4,4)\n",
    "    plt.plot(x, y4)\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "322fae49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 43780 characters]\n",
      "text/plain": [
       "<Figure size 1000x1000 with 4 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(-10,10)\n",
    "myPlots(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1637262f",
   "metadata": {},
   "source": [
    "## Age classificator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "25857354",
   "metadata": {},
   "outputs": [],
   "source": [
    "def AgeClassificator(age):\n",
    "    if age<=2:\n",
    "        print('You are a baby')\n",
    "    else: \n",
    "        if age <=12:\n",
    "            print('you are a children')\n",
    "        else:\n",
    "            if age<=18:\n",
    "                print('you are a teenager')\n",
    "            else:\n",
    "                if age <=40:\n",
    "                    print('you are young')\n",
    "                else:\n",
    "                    print('You are old-younger')\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "744b17f9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You are old-younger\n"
     ]
    }
   ],
   "source": [
    "AgeClassificator(41)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
