{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["# SET UP"],"metadata":{"id":"a_-J3h51pgpA"}},{"cell_type":"markdown","source":["###1. **Libraries**"],"metadata":{"id":"Wv-IuU8c5FHc"}},{"cell_type":"markdown","source":["* install libraries\n","* import libraries\n"],"metadata":{"id":"r1xbTAUVAtWs"}},{"cell_type":"code","source":["!pip install torchsummaryX==1.1.0 wandb onnx --quiet"],"metadata":{"id":"heZksa1pA8NF","colab":{"base_uri":"https://localhost:8080/"},"outputId":"646f0782-80c7-4d6a-fbba-ea92bb6d7981"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/16.0 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.2/16.0 MB\u001b[0m \u001b[31m5.3 MB/s\u001b[0m eta \u001b[36m0:00:03\u001b[0m\r\u001b[2K   \u001b[91m━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/16.0 MB\u001b[0m \u001b[31m21.5 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.0/16.0 MB\u001b[0m \u001b[31m57.0 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━\u001b[0m \u001b[32m11.8/16.0 MB\u001b[0m \u001b[31m148.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m16.0/16.0 MB\u001b[0m \u001b[31m151.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m16.0/16.0 MB\u001b[0m \u001b[31m151.6 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m16.0/16.0 MB\u001b[0m \u001b[31m76.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n","\u001b[?25h"]}]},{"cell_type":"code","source":["import torch\n","import numpy as np\n","from torchsummaryX import summary"],"metadata":{"id":"Dug7vU3aA1IH"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["###2. **Files**"],"metadata":{"id":"wXdiPdocBeA9"}},{"cell_type":"code","source":["import pandas as pd\n","data = pd.read_csv('/content/sample_data/california_housing_test.csv')\n","data.head(3)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":143},"id":"XnYTzBmwBkT2","outputId":"0bfbd5e4-e88c-465f-b351-cb81a1778659"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["   longitude  latitude  housing_median_age  total_rooms  total_bedrooms  \\\n","0    -122.05     37.37                27.0       3885.0           661.0   \n","1    -118.30     34.26                43.0       1510.0           310.0   \n","2    -117.81     33.78                27.0       3589.0           507.0   \n","\n","   population  households  median_income  median_house_value  \n","0      1537.0       606.0         6.6085            344700.0  \n","1       809.0       277.0         3.5990            176500.0  \n","2      1484.0       495.0         5.7934            270500.0  "],"text/html":["\n","  <div id=\"df-c42bae26-a866-4507-a9b7-90c754020b8e\" class=\"colab-df-container\">\n","    <div>\n","<style scoped>\n","    .dataframe tbody tr th:only-of-type {\n","        vertical-align: middle;\n","    }\n","\n","    .dataframe tbody tr th {\n","        vertical-align: top;\n","    }\n","\n","    .dataframe thead th {\n","        text-align: right;\n","    }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n","  <thead>\n","    <tr style=\"text-align: right;\">\n","      <th></th>\n","      <th>longitude</th>\n","      <th>latitude</th>\n","      <th>housing_median_age</th>\n","      <th>total_rooms</th>\n","      <th>total_bedrooms</th>\n","      <th>population</th>\n","      <th>households</th>\n","      <th>median_income</th>\n","      <th>median_house_value</th>\n","    </tr>\n","  </thead>\n","  <tbody>\n","    <tr>\n","      <th>0</th>\n","      <td>-122.05</td>\n","      <td>37.37</td>\n","      <td>27.0</td>\n","      <td>3885.0</td>\n","      <td>661.0</td>\n","      <td>1537.0</td>\n","      <td>606.0</td>\n","      <td>6.6085</td>\n","      <td>344700.0</td>\n","    </tr>\n","    <tr>\n","      <th>1</th>\n","      <td>-118.30</td>\n","      <td>34.26</td>\n","      <td>43.0</td>\n","      <td>1510.0</td>\n","      <td>310.0</td>\n","      <td>809.0</td>\n","      <td>277.0</td>\n","      <td>3.5990</td>\n","      <td>176500.0</td>\n","    </tr>\n","    <tr>\n","      <th>2</th>\n","      <td>-117.81</td>\n","      <td>33.78</td>\n","      <td>27.0</td>\n","      <td>3589.0</td>\n","      <td>507.0</td>\n","      <td>1484.0</td>\n","      <td>495.0</td>\n","      <td>5.7934</td>\n","      <td>270500.0</td>\n","    </tr>\n","  </tbody>\n","</table>\n","</div>\n","    <div class=\"colab-df-buttons\">\n","\n","  <div class=\"colab-df-container\">\n","    <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c42bae26-a866-4507-a9b7-90c754020b8e')\"\n","            title=\"Convert this dataframe to an interactive table.\"\n","            style=\"display:none;\">\n","\n","  <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n","    <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n","  </svg>\n","    </button>\n","\n","  <style>\n","    .colab-df-container {\n","      display:flex;\n","      gap: 12px;\n","    }\n","\n","    .colab-df-convert {\n","      background-color: #E8F0FE;\n","      border: none;\n","      border-radius: 50%;\n","      cursor: pointer;\n","      display: none;\n","      fill: #1967D2;\n","      height: 32px;\n","      padding: 0 0 0 0;\n","      width: 32px;\n","    }\n","\n","    .colab-df-convert:hover {\n","      background-color: #E2EBFA;\n","      box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n","      fill: #174EA6;\n","    }\n","\n","    .colab-df-buttons div {\n","      margin-bottom: 4px;\n","    }\n","\n","    [theme=dark] .colab-df-convert {\n","      background-color: #3B4455;\n","      fill: #D2E3FC;\n","    }\n","\n","    [theme=dark] .colab-df-convert:hover {\n","      background-color: #434B5C;\n","      box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n","      filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n","      fill: #FFFFFF;\n","    }\n","  </style>\n","\n","    <script>\n","      const buttonEl =\n","        document.querySelector('#df-c42bae26-a866-4507-a9b7-90c754020b8e button.colab-df-convert');\n","      buttonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","      async function convertToInteractive(key) {\n","        const element = document.querySelector('#df-c42bae26-a866-4507-a9b7-90c754020b8e');\n","        const dataTable =\n","          await google.colab.kernel.invokeFunction('convertToInteractive',\n","                                                    [key], {});\n","        if (!dataTable) return;\n","\n","        const docLinkHtml = 'Like what you see? Visit the ' +\n","          '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n","          + ' to learn more about interactive tables.';\n","        element.innerHTML = '';\n","        dataTable['output_type'] = 'display_data';\n","        await google.colab.output.renderOutput(dataTable, element);\n","        const docLink = document.createElement('div');\n","        docLink.innerHTML = docLinkHtml;\n","        element.appendChild(docLink);\n","      }\n","    </script>\n","  </div>\n","\n","\n","<div id=\"df-057c55b1-bd65-4e2b-8dcd-e257740880bb\">\n","  <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-057c55b1-bd65-4e2b-8dcd-e257740880bb')\"\n","            title=\"Suggest charts\"\n","            style=\"display:none;\">\n","\n","<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","     width=\"24px\">\n","    <g>\n","        <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n","    </g>\n","</svg>\n","  </button>\n","\n","<style>\n","  .colab-df-quickchart {\n","      --bg-color: #E8F0FE;\n","      --fill-color: #1967D2;\n","      --hover-bg-color: #E2EBFA;\n","      --hover-fill-color: #174EA6;\n","      --disabled-fill-color: #AAA;\n","      --disabled-bg-color: #DDD;\n","  }\n","\n","  [theme=dark] .colab-df-quickchart {\n","      --bg-color: #3B4455;\n","      --fill-color: #D2E3FC;\n","      --hover-bg-color: #434B5C;\n","      --hover-fill-color: #FFFFFF;\n","      --disabled-bg-color: #3B4455;\n","      --disabled-fill-color: #666;\n","  }\n","\n","  .colab-df-quickchart {\n","    background-color: var(--bg-color);\n","    border: none;\n","    border-radius: 50%;\n","    cursor: pointer;\n","    display: none;\n","    fill: var(--fill-color);\n","    height: 32px;\n","    padding: 0;\n","    width: 32px;\n","  }\n","\n","  .colab-df-quickchart:hover {\n","    background-color: var(--hover-bg-color);\n","    box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n","    fill: var(--button-hover-fill-color);\n","  }\n","\n","  .colab-df-quickchart-complete:disabled,\n","  .colab-df-quickchart-complete:disabled:hover {\n","    background-color: var(--disabled-bg-color);\n","    fill: var(--disabled-fill-color);\n","    box-shadow: none;\n","  }\n","\n","  .colab-df-spinner {\n","    border: 2px solid var(--fill-color);\n","    border-color: transparent;\n","    border-bottom-color: var(--fill-color);\n","    animation:\n","      spin 1s steps(1) infinite;\n","  }\n","\n","  @keyframes spin {\n","    0% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","      border-left-color: var(--fill-color);\n","    }\n","    20% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    30% {\n","      border-color: transparent;\n","      border-left-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","      border-right-color: var(--fill-color);\n","    }\n","    40% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-top-color: var(--fill-color);\n","    }\n","    60% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","    }\n","    80% {\n","      border-color: transparent;\n","      border-right-color: var(--fill-color);\n","      border-bottom-color: var(--fill-color);\n","    }\n","    90% {\n","      border-color: transparent;\n","      border-bottom-color: var(--fill-color);\n","    }\n","  }\n","</style>\n","\n","  <script>\n","    async function quickchart(key) {\n","      const quickchartButtonEl =\n","        document.querySelector('#' + key + ' button');\n","      quickchartButtonEl.disabled = true;  // To prevent multiple clicks.\n","      quickchartButtonEl.classList.add('colab-df-spinner');\n","      try {\n","        const charts = await google.colab.kernel.invokeFunction(\n","            'suggestCharts', [key], {});\n","      } catch (error) {\n","        console.error('Error during call to suggestCharts:', error);\n","      }\n","      quickchartButtonEl.classList.remove('colab-df-spinner');\n","      quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n","    }\n","    (() => {\n","      let quickchartButtonEl =\n","        document.querySelector('#df-057c55b1-bd65-4e2b-8dcd-e257740880bb button');\n","      quickchartButtonEl.style.display =\n","        google.colab.kernel.accessAllowed ? 'block' : 'none';\n","    })();\n","  </script>\n","</div>\n","\n","    </div>\n","  </div>\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"data","summary":"{\n  \"name\": \"data\",\n  \"rows\": 3000,\n  \"fields\": [\n    {\n      \"column\": \"longitude\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1.9949362939550161,\n        \"min\": -124.18,\n        \"max\": -114.49,\n        \"num_unique_values\": 607,\n        \"samples\": [\n          -121.15,\n          -121.46,\n          -121.02\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"latitude\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 2.1296695233438325,\n        \"min\": 32.56,\n        \"max\": 41.92,\n        \"num_unique_values\": 587,\n        \"samples\": [\n          40.17,\n          33.69,\n          39.61\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"housing_median_age\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 12.555395554955755,\n        \"min\": 1.0,\n        \"max\": 52.0,\n        \"num_unique_values\": 52,\n        \"samples\": [\n          14.0,\n          49.0,\n          7.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"total_rooms\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 2155.59333162558,\n        \"min\": 6.0,\n        \"max\": 30450.0,\n        \"num_unique_values\": 2215,\n        \"samples\": [\n          1961.0,\n          1807.0,\n          680.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"total_bedrooms\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 415.6543681363232,\n        \"min\": 2.0,\n        \"max\": 5419.0,\n        \"num_unique_values\": 1055,\n        \"samples\": [\n          532.0,\n          764.0,\n          2162.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"population\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1030.5430124122422,\n        \"min\": 5.0,\n        \"max\": 11935.0,\n        \"num_unique_values\": 1802,\n        \"samples\": [\n          947.0,\n          1140.0,\n          2019.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"households\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 365.42270980552604,\n        \"min\": 2.0,\n        \"max\": 4930.0,\n        \"num_unique_values\": 1026,\n        \"samples\": [\n          646.0,\n          629.0,\n          504.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"median_income\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 1.854511729691481,\n        \"min\": 0.4999,\n        \"max\": 15.0001,\n        \"num_unique_values\": 2578,\n        \"samples\": [\n          1.725,\n          0.7403,\n          2.6964\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    },\n    {\n      \"column\": \"median_house_value\",\n      \"properties\": {\n        \"dtype\": \"number\",\n        \"std\": 113119.68746964433,\n        \"min\": 22500.0,\n        \"max\": 500001.0,\n        \"num_unique_values\": 1784,\n        \"samples\": [\n          71900.0,\n          63000.0,\n          115800.0\n        ],\n        \"semantic_type\": \"\",\n        \"description\": \"\"\n      }\n    }\n  ]\n}"}},"metadata":{},"execution_count":11}]},{"cell_type":"markdown","source":["# DATA TYPES AND SLICING"],"metadata":{"id":"114aKInp4khU"}},{"cell_type":"markdown","source":["###1. **Numeric Data Types**\n","* integer (int) represents whole number\n","* floating point type (float) represents decimal numbers\n","\n","\n","\n"],"metadata":{"id":"xL5sbWl4s9OT"}},{"cell_type":"code","source":["age = 23  #int\n","pi = 3.14 #float\n","temperature = -5.5 #float\n","\n","print(\"data type of variable age = \", type(age))\n","print(\"data type of variable pi = \", type(pi))\n","print(\"data type of variable temperature = \", type(temperature))"],"metadata":{"id":"840Lx4V2pweW","colab":{"base_uri":"https://localhost:8080/"},"outputId":"793e2416-140b-4d45-8693-46c9a635ce8f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["data type of variable age =  <class 'int'>\n","data type of variable pi =  <class 'float'>\n","data type of variable temperature =  <class 'float'>\n"]}]},{"cell_type":"markdown","source":["*Slicing into integers and floats*\n","* TypeErrors will arise from slicing into ints and floats\n"],"metadata":{"id":"qqlr_C6rMxrL"}},{"cell_type":"code","source":["print(age[0])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":141},"id":"Dmzu1ibtCrrr","outputId":"697734d8-466c-45b3-e787-66828601c16b"},"execution_count":null,"outputs":[{"output_type":"error","ename":"TypeError","evalue":"'int' object is not subscriptable","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-9-b4d90e3c06a9>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mage\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mTypeError\u001b[0m: 'int' object is not subscriptable"]}]},{"cell_type":"code","source":["print(pi[0])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":141},"id":"qfWr4BRfNLsG","outputId":"bec3a5ff-7319-4289-aa70-6f679755d399"},"execution_count":null,"outputs":[{"output_type":"error","ename":"TypeError","evalue":"'float' object is not subscriptable","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-12-51206bc88f5a>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpi\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mTypeError\u001b[0m: 'float' object is not subscriptable"]}]},{"cell_type":"markdown","source":["###2. **String Data Type**\n","  String (str) represents sequence of characters enclosed by double quotes or single quotes."],"metadata":{"id":"RudLM1JbuSKU"}},{"cell_type":"code","source":["name = \"Alice\"\n","greeting = 'Hello'\n","address = \"123 Main St\"\n","\n","print(\"Data type of the variable name = \",type(name))\n","print(\"Data type of the variable greeting = \",type(greeting))\n","print(\"Data type of the variable address = \",type(address))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QZL-M91uuQyZ","outputId":"3eb47a76-6cff-4050-9267-6a0259d1f83c"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["data type of the variable name =  <class 'str'>\n","data type of the variable greeting =  <class 'str'>\n","data type of the variable address =  <class 'str'>\n"]}]},{"cell_type":"code","source":["# slice only one element\n","print(\"The first letter of the name is:\", name[0])\n","print(\"The last letter of the name is:\", name[-1])\n","\n","# slice a range of elements\n","print(\"The second letter to the fourth of the name is:\", name[1:4])\n","print(\"The first two letters of the name are:\", name[:2])\n","print(\"Substring starting from the third letter is:\", name[2:])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"5mfNcLRtCv2v","outputId":"e58f0aa3-1065-407d-da6f-cbc9128d8cd8"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["The first letter of the name is: A\n","The last letter of the name is: e\n","The second letter to the fourth of the name is: lic\n","The first two letters of the name are: Al\n","Substring starting from the third letter is: ice\n"]}]},{"cell_type":"markdown","source":["###3. **Boolean Type**\n","\n","Boolean (bool) represents a boolean value, either True or False."],"metadata":{"id":"aa9hpHBXvo8S"}},{"cell_type":"code","source":["is_student = True\n","has_license = False\n","\n","print(\"data type of the variable is_student = \",type(is_student))\n","print(\"data type of the variable has_license = \",type(has_license))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ypssh6MOv6EF","outputId":"a36041bf-8c50-49d0-cfb3-9366f36fdd2f"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["data type of the variable is_student =  <class 'bool'>\n","data type of the variable has_license =  <class 'bool'>\n"]}]},{"cell_type":"markdown","source":["###4. **List**\n","    \n","List (list) represents an ordered, mutable collection of elements."],"metadata":{"id":"1rOmwvohwUdX"}},{"cell_type":"code","source":["list1 = [1, 2, 3, 4]\n","mixed_list = [12, \"Hello\", True]"],"metadata":{"id":"xi0bFzgJwim0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["print(\"First element:\", list1[0])\n","print(\"Last two elements:\", list1[2:])\n","print(\"Middle two elements:\", list1[1:3])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"AQsjb3cWFYdV","outputId":"753a3ef3-538a-445f-f1fa-ad2f58233b06"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["First element: 1\n","Last two elements: [3, 4]\n","Middle two elements: [2, 3]\n"]}]},{"cell_type":"code","source":["# List is mutable\n","mixed_list[0] = False\n","mixed_list"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Tq3v3RbJZwG3","outputId":"bc350975-bc57-4997-8616-9b43c32f342f"},"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[False, 'Hello', True]"]},"metadata":{},"execution_count":18}]},{"cell_type":"markdown","source":["###5. **Tuple**\n","\n","Tuple (tuple) represents an ordered, immutable collection of elements."],"metadata":{"id":"Q8ufYlWVxGVE"}},{"cell_type":"code","source":["colors = ('red', 'green', 'yellow', 'blue')"],"metadata":{"id":"JiuVpd_1xb3J"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["print(\"First element:\", colors[0])\n","print(\"Last two elements:\", colors[2:])\n","print(\"Middle two elements:\", colors[1:3])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jyPYHDNWFloM","outputId":"a0b52053-4d5c-4af4-d856-922a9575c0bc"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["First element: red\n","Last two elements: ('yellow', 'blue')\n","Middle two elements: ('green', 'yellow')\n"]}]},{"cell_type":"markdown","source":["*Assignment with Tuples*\n","* Type Errors will arise from Assigning elements to indices in tuples\n"],"metadata":{"id":"8L3ylz1cNdPn"}},{"cell_type":"code","source":["colors[0] = 'purple'\n","colors"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":159},"id":"8OF5-rhSZue0","outputId":"dd3bfa69-9661-417b-fceb-c09a60825ccc"},"execution_count":null,"outputs":[{"output_type":"error","ename":"TypeError","evalue":"'tuple' object does not support item assignment","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-21-4393bb1eea3b>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcolors\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'purple'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mcolors\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"]}]},{"cell_type":"markdown","source":["###6. **Set**\n","\n","Set (set) represents an unordered, immutable collection of elements that are unique."],"metadata":{"id":"km5FtspMbZ-y"}},{"cell_type":"code","source":["unique_numbers = {1,2,3,3,3,3,4,5}\n","\n","print(unique_numbers)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"59IBkfYqbYPa","outputId":"502ccef4-b767-4c3c-dc7f-8d845e79cb27"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["{1, 2, 3, 4, 5}\n"]}]},{"cell_type":"code","source":["unique_numbers2 = {2,1,3,3,3,3,4,5}\n","\n","print(unique_numbers2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gouZ51pRjbZQ","outputId":"f16257f2-e1a5-4510-ce16-f181b1e92eaa"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["{1, 2, 3, 4, 5}\n"]}]},{"cell_type":"markdown","source":["*Indexing into a Set*\n","* KeyErrors will arise from indexing into a Set\n"],"metadata":{"id":"wAKu6aypOLGz"}},{"cell_type":"code","source":["unique_numbers[0]"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":141},"id":"1qHn6lg7N_8M","outputId":"494f7ec8-6215-4a39-eda7-ade10245db53"},"execution_count":null,"outputs":[{"output_type":"error","ename":"TypeError","evalue":"'set' object is not subscriptable","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-28-a8a35a692b7e>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0munique_numbers\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mTypeError\u001b[0m: 'set' object is not subscriptable"]}]},{"cell_type":"markdown","source":["###7. **Dictionary**\n","\n","* Dictionary 'dict' represents a collection of key-value pairs.\n","* dictionaries are unordered collections of items (similar to sets)"],"metadata":{"id":"DfKZNz-IxqHG"}},{"cell_type":"code","source":["person = {'name':'John','age':30,'city':'Pittsburgh'}\n","\n","print(f\"Hello my name is {person['name']}. I am {person['age']} years old and I live at {person['city']}.\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"A4LLvVQtx5kg","outputId":"4e06ef37-15b6-4167-b024-bdfb98453b17"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Hello my name is John. I am 30 years old and I live at Pittsburgh.\n"]}]},{"cell_type":"code","source":["print(\"All keys:\", list(person.keys()))\n","print(\"All values:\", list(person.values()))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"L_orGNDJEycM","outputId":"126a02dd-3502-48ac-a050-4019180db1b5"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["All keys: ['name', 'age', 'city']\n","All values: ['John', 30, 'Pittsburgh']\n"]}]},{"cell_type":"markdown","source":["*Indexing into a Dictionary*\n","* KeyErrors will arise from indexing into a Dictionary incorrectly\n"],"metadata":{"id":"_a30hNHANtuw"}},{"cell_type":"code","source":["person[0]"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":141},"id":"p_pHwTkZEuBX","outputId":"18fb1436-a588-433b-e4bf-10144fadd6c7"},"execution_count":null,"outputs":[{"output_type":"error","ename":"KeyError","evalue":"0","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)","\u001b[0;32m<ipython-input-25-d40e6f33acad>\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mperson\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mKeyError\u001b[0m: 0"]}]},{"cell_type":"markdown","source":["###8. **NoneType**\n","\n","It represents the absence of a value, which similar to null in other languages"],"metadata":{"id":"vsRQ6Qtn0aKk"}},{"cell_type":"code","source":["result = None"],"metadata":{"id":"QCPIZk8q0ugj"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["# LOGICAL STATEMENTS AND LOOPS"],"metadata":{"id":"dujNkwzapw5u"}},{"cell_type":"markdown","source":["###1. **if and else statement :**\n","\n","It allows conditional execution of code based on the evaluation of a given condition.\n"],"metadata":{"id":"va3q9uIpvmoy"}},{"cell_type":"code","source":["num = 10\n","if num > 0:\n","    print(\"Positive\")\n","else:\n","    print(\"Non-positive\")\n"],"metadata":{"id":"Li-d7Tgfp7vN","colab":{"base_uri":"https://localhost:8080/"},"outputId":"4bb9cb5e-fdff-49da-c2e6-21a0c0cf969e"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Positive\n"]}]},{"cell_type":"markdown","source":["###2. **and, or, and not operators:**\n","\n","  These operators are used for combining conditions and negating them.\n"],"metadata":{"id":"UvQcAxW82IYa"}},{"cell_type":"code","source":["x = 5\n","y = 10\n","if x > 0 and y < 20:\n","    print(\"Both conditions are true\")\n","if x > 0 or y > 20:\n","    print(\"At least one condition is true\")\n","if not x == 0:\n","    print(\"x is not equal to 0\")\n","\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"f9Tadjb52TNJ","outputId":"99781eda-472f-40c9-d2ab-8d043fb78b20"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Both conditions are true\n","At least one condition is true\n","x is not equal to 0\n"]}]},{"cell_type":"markdown","source":["###3. **for  loop:**\n","\n","It iterates over a sequence (e.g., list, tuple, string) and performs actions for each element.\n"],"metadata":{"id":"VAGaG_Ot2gOm"}},{"cell_type":"code","source":["fruits = [\"apple\", \"banana\",\"cherry\"]\n","\n","for fruit in fruits:\n","    print(fruit)\n","\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"Scwqs21u2iYo","outputId":"d8d92f63-b108-4f5f-95b4-a8f3f0695c26"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["apple\n","banana\n","cherry\n"]}]},{"cell_type":"markdown","source":["###4. **while  loop:**"],"metadata":{"id":"bFg2R7pRZtUl"}},{"cell_type":"code","source":["count = 0\n","while count < 5:\n","    print(\"Count is:\", count)\n","    count += 1\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jnPjbrmL2vLs","outputId":"df77d582-3f8d-4322-e9cc-11056f97ccff"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Count is: 0\n","Count is: 1\n","Count is: 2\n","Count is: 3\n","Count is: 4\n"]}]},{"cell_type":"markdown","source":["###5. **Break and continue:**\n","\n","Break terminates the loop as soon as it is encountered.\n","Continue skips the current iteration of the loop.\n"],"metadata":{"id":"-Hl3vd0nPPgQ"}},{"cell_type":"code","source":["fruits = [\"apple\", \"banana\", \"orange\"]\n","\n","print(\"loop 1\")\n","for fruit in fruits:\n","  print(fruit)\n","  if fruit == \"apple\":\n","    break"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"PakAQjtuPhU1","outputId":"b74abd02-d06b-4e65-aac1-bf39c0153812"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["loop 1\n","apple\n"]}]},{"cell_type":"code","source":["print(\"loop 2\")\n","for fruit in fruits:\n","  if fruit == \"apple\":\n","    continue\n","  else:\n","      print(fruit)\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"MOg9iOS2QmRJ","outputId":"ee9a1ded-f290-42e6-ff7e-5db52f93cd02"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["loop 2\n","banana\n","orange\n"]}]},{"cell_type":"markdown","source":["# FUNCTIONS"],"metadata":{"id":"wPvipry-p-PW"}},{"cell_type":"markdown","source":["###1. **Built-in Functions**\n","\n","print(), min(), max(), len(), range(), type() etc.\n","\n","  These functions are already provided as part of python."],"metadata":{"id":"klaL441u24-u"}},{"cell_type":"code","source":["fruits = [\"apple\", \"banana\",\"cherry\"]\n","print(len(fruits))\n"],"metadata":{"id":"344GDlvRqBzF","colab":{"base_uri":"https://localhost:8080/"},"outputId":"c81af3a5-8f9f-4487-ef22-db688bf14399"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["3\n"]}]},{"cell_type":"markdown","source":["###2.  **Built-in Methods**\n","\n","  Data types in python have “methods” associated with them - functions specifically designed to operate on instances of that data type\n"],"metadata":{"id":"UYX3dbVC3RuH"}},{"cell_type":"code","source":["name = \"john\"\n","print(\"Name in upper case = \", name.upper())\n","\n","l = [1,2,3,4]\n","l.append(5)\n","print(\"List after appending\",l)\n","\n","person = {'name':'John','age':30,'city':'Pitt'}\n","print(\"Keys of the dictionary person\", person.keys())\n","\n","# for more methods explore https://www.w3schools.com/python/python_ref_functions.asp"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"RkPpeWJg3kGt","outputId":"db4e8b6c-a9e4-4e8e-8791-0ceccd90211a"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Name in upper case =  JOHN\n","List after appending [1, 2, 3, 4, 5]\n","Keys of the dictionary person dict_keys(['name', 'age', 'city'])\n"]}]},{"cell_type":"markdown","source":["###3. **User Defined Functions**\n","\n","  Functions we define ourselves to perform specific task.\n","\n","  User-defined functions help to decompose a large program into small segments which makes the program easy to understand, maintain and debug.\n"],"metadata":{"id":"dPOv62Y65Pex"}},{"cell_type":"code","source":["def print_something():\n","    if 3 < 5:\n","        print(\"Dumb! 3 is always less than 5\")\n","    else:\n","        print(\"I can never reach here\")\n","    return\n","\n","print_something()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"z_RT7iYB5NyM","outputId":"fc85ce6d-d601-49e2-ad66-dc0a2cce8f89"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Dumb! 3 is always less than 5\n"]}]},{"cell_type":"markdown","source":["###4. **Local and Global Variables**\n","\n","\n","Global variables are defined outside the functions, and are accessible everywhere in the program.\n","\n","Local variables are defined inside a function, and can only be accessed inside that function.\n"],"metadata":{"id":"n7jzvD6PXNlF"}},{"cell_type":"code","source":["fruit = \"apple\"\n","def fav_fruit():\n","  print(\"my favorite fruit is \", fruit)\n","\n","fav_fruit()\n","print(fruit)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"gzdZjbm2XnBX","outputId":"6afa5d60-508e-4314-eb3e-fde4ec3be921"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["my favorite fruit is  apple\n","apple\n"]}]},{"cell_type":"code","source":["def fav_vegetable():\n","  vegetable = \"onion\"\n","  print(\"my favorite vegetable is \", vegetable)\n","\n","fav_vegetable()\n","print(vegetable)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":193},"id":"37d8jt2FX-Yb","outputId":"7931cb76-898a-4971-dac2-9dfc5d67193e"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["my favorite vegetable is  onion\n"]},{"output_type":"error","ename":"NameError","evalue":"name 'vegetable' is not defined","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-40-b1e2cd878cd0>\u001b[0m in \u001b[0;36m<cell line: 6>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mfav_vegetable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvegetable\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mNameError\u001b[0m: name 'vegetable' is not defined"]}]},{"cell_type":"markdown","source":["### 4. **Recursion**\n","\n","1. What is Recursion?\n","   - Recursion is a programming technique where a function calls itself to solve a problem.\n","\n","2. Key Concepts:\n","   - Base Case: The condition that stops the recursion.\n","   - Recursive Case: The problem is broken down into smaller sub-problems of the same type.\n","\n","3. How Recursion Works:\n","   - Function calls itself until base case is reached.\n","   - Smaller sub-problems are solved before combining results.\n","\n","4. Example: Factorial Calculation\n","   - n! = n * (n-1) * (n-2) * ... * 1\n","   - Base case: 0! = 1\n","   - Recursive case: n! = n * (n-1)!\n","\n"],"metadata":{"id":"OjK2ItkN5fbD"}},{"cell_type":"code","source":["def fibonacci(n):\n","    # Base cases: fibonacci(0) is 0, fibonacci(1) is 1\n","    if n == 0: return 0\n","    elif n == 1: return 1\n","    # Recursive case: fibonacci(n) = fibonacci(n-1) + fibonacci(n-2)\n","    else: return fibonacci(n - 1) + fibonacci(n - 2)\n","\n","print(\"Fibonacci of 8 is\",fibonacci(8))\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"siNRHqvO5en8","outputId":"3c62e72c-07dd-4537-ace9-cdfc9321c865"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Fibonacci of 8 is 21\n"]}]},{"cell_type":"markdown","source":["# EXCEPTION AND ERROR HANDLING"],"metadata":{"id":"fptL1sP7qCWm"}},{"cell_type":"markdown","source":["\n","\n","1.  **SyntaxError :**\n","\n"," Occurs when the code violates the Python syntax rules.\n","\n","\n"],"metadata":{"id":"Y_pxW_nP6H9W"}},{"cell_type":"code","source":["print(\"Hello World!\"\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":106},"id":"5fyl9m3_7Zz9","outputId":"e7687e9d-30b4-4162-ceca-a32ef598813c"},"execution_count":null,"outputs":[{"output_type":"error","ename":"SyntaxError","evalue":"incomplete input (<ipython-input-42-4459da64a047>, line 1)","traceback":["\u001b[0;36m  File \u001b[0;32m\"<ipython-input-42-4459da64a047>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m    print(\"Hello, World!\"\u001b[0m\n\u001b[0m                         ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m incomplete input\n"]}]},{"cell_type":"markdown","source":["2. **IndentationError :**\n","\n"," Occurs when there are issues with the indentation of code blocks.\n","\n"],"metadata":{"id":"3NuFFzos6Q_r"}},{"cell_type":"code","source":["if True:\n","print(\"First line\")\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":106},"id":"GHKmAyxa7alz","outputId":"3f81aad8-e926-4306-f93a-2383530eecf8"},"execution_count":null,"outputs":[{"output_type":"error","ename":"IndentationError","evalue":"expected an indented block after 'if' statement on line 1 (<ipython-input-43-952674ffee40>, line 2)","traceback":["\u001b[0;36m  File \u001b[0;32m\"<ipython-input-43-952674ffee40>\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m    print(\"First line\")\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mIndentationError\u001b[0m\u001b[0;31m:\u001b[0m expected an indented block after 'if' statement on line 1\n"]}]},{"cell_type":"markdown","source":["3. **NameError :**\n","\n","  Occurs when a variable or a function is not defined."],"metadata":{"id":"ZEwBriR96ZUy"}},{"cell_type":"code","source":["X = 10\n","print(Y)"],"metadata":{"id":"1BRt_aTPqJaJ","colab":{"base_uri":"https://localhost:8080/","height":159},"outputId":"c342e099-5fe4-4205-be20-7440daa35073"},"execution_count":null,"outputs":[{"output_type":"error","ename":"NameError","evalue":"name 'Y' is not defined","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-44-7d9befca009a>\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mY\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mNameError\u001b[0m: name 'Y' is not defined"]}]},{"cell_type":"markdown","source":["4. **TypeError :**\n","\n"," Occurs when an operation is performed on incompatible data types.\n"],"metadata":{"id":"m6xXdPFC6mSc"}},{"cell_type":"code","source":["a = \"5\"\n","b = 3\n","result = a + b\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":176},"id":"9KKmxbNU7bqQ","outputId":"ba79e31a-a570-499c-f8d7-169574531622"},"execution_count":null,"outputs":[{"output_type":"error","ename":"TypeError","evalue":"can only concatenate str (not \"int\") to str","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)","\u001b[0;32m<ipython-input-45-d0db3c2a5c84>\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"5\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"]}]},{"cell_type":"markdown","source":["5. **IndexError :**\n","\n"," Occurs when attempting to access an index that is out of range.\n"],"metadata":{"id":"vc_jfHW96w1P"}},{"cell_type":"code","source":["my_list = [1, 2, 3]\n","print(my_list[3])\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":159},"id":"Q_UocBIy7ccY","outputId":"99c2080c-6599-495f-fd3b-cd017ba78349"},"execution_count":null,"outputs":[{"output_type":"error","ename":"IndexError","evalue":"list index out of range","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)","\u001b[0;32m<ipython-input-46-d54d0dfa12f9>\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mmy_list\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_list\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mIndexError\u001b[0m: list index out of range"]}]},{"cell_type":"markdown","source":["6. **KeyError :**\n","\n"," Occurs when accessing a dictionary key that doesn't exist.\n"],"metadata":{"id":"280jLB_364TB"}},{"cell_type":"code","source":["my_dict = {'a': 1, 'b': 2}\n","print(my_dict['c'])\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":159},"id":"S8EugALw7dWz","outputId":"9ae90929-7422-444d-b560-043a6166676b"},"execution_count":null,"outputs":[{"output_type":"error","ename":"KeyError","evalue":"'c'","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)","\u001b[0;32m<ipython-input-47-afd92c76bdae>\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mmy_dict\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m'a'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'b'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmy_dict\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'c'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mKeyError\u001b[0m: 'c'"]}]},{"cell_type":"markdown","source":["7. **ZeroDivisionError :**\n","\n"," Occurs when dividing by zero.\n"],"metadata":{"id":"Du631gPl7Agj"}},{"cell_type":"code","source":["x = 10\n","y = 0\n","result = x / y"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":176},"id":"9dn1YMgi7HeL","outputId":"9bf40419-bc33-4ec6-a040-2a577df497dc"},"execution_count":null,"outputs":[{"output_type":"error","ename":"ZeroDivisionError","evalue":"division by zero","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mZeroDivisionError\u001b[0m                         Traceback (most recent call last)","\u001b[0;32m<ipython-input-48-c46bf7a9ee04>\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"]}]},{"cell_type":"markdown","source":["8. **NotImplementedError:**\n","\n"," Occurs when a method or function lacks implementation but is called by the code.\n","\n"],"metadata":{"id":"OCifB7dq7Mur"}},{"cell_type":"code","source":["def my_function():\n","   raise NotImplementedError(\"Not Present\")\n","\n","my_function()\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":280},"id":"BrDfRKzJ7eGm","outputId":"18f2cd39-8f1a-40e2-9a3f-d46b4a290286"},"execution_count":null,"outputs":[{"output_type":"error","ename":"NotImplementedError","evalue":"Not Present","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mNotImplementedError\u001b[0m                       Traceback (most recent call last)","\u001b[0;32m<ipython-input-49-a85e4bf504b3>\u001b[0m in \u001b[0;36m<cell line: 4>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      2\u001b[0m    \u001b[0;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Not Present\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mmy_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m<ipython-input-49-a85e4bf504b3>\u001b[0m in \u001b[0;36mmy_function\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmy_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m    \u001b[0;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Not Present\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mmy_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mNotImplementedError\u001b[0m: Not Present"]}]}]}