├── 01. Introduction to Python ├── 1. Variables.ipynb ├── 2. Python numbers.ipynb ├── 3. Arithmetic Operators.ipynb ├── 4. Taking inputs.ipynb ├── Assignment (1).ipynb └── Introduction to Python.pdf ├── 02. Conditionals and Loops ├── 1. Operators & Else If.ipynb ├── 2. Nested Conditionals & While Loop.ipynb ├── 3. Primality Checking .ipynb ├── Assignment (2).ipynb └── Conditionals and Loops.pdf ├── 03. Patterns 1 ├── 1. Patterns.ipynb ├── 2. Square Patterns.ipynb ├── 3. Triangular patterns.ipynb ├── 4. Character Patterns.ipynb ├── Assignment (3).ipynb └── Patterns 1.pdf ├── 04. Patterns 2 ├── 1. Inverted triangle.ipynb ├── 2. Reversed Pattern & iso.ipynb ├── Assignment (4).ipynb └── Patterns 2.pdf ├── 05. More on Loops ├── 1. forloop.ipynb ├── 2. KEYWORDS.ipynb ├── Assignment (5).ipynb └── More On Loops.pdf ├── 06. Functions ├── 1. Functions.ipynb ├── 2. Scope of Variables.ipynb ├── 3. Default parameters in functions.ipynb ├── Assignment (6).ipynb └── Functions.pdf ├── 07. List & Arrays ├── 1. Operations in list.ipynb ├── 2. Looping on list.ipynb ├── 3. Negative indexing & Sequencing in list.ipynb ├── 4. Taking input in list.ipynb ├── 5. Linear Search.ipynb ├── 6. Linear Search Through Functions.ipynb ├── 7. Mutable And Immutable Concept.ipynb ├── 8. Passing V & L Through Functions.ipynb ├── 9. Reverse List.ipynb ├── Assignment (7).ipynb └── Lists and Arrays .pdf ├── 08. Searching and Sorting ├── 1. Binary Search.ipynb ├── 2. Selection Sort.ipynb ├── 3. Bubble Sort.ipynb ├── 4. Insertion Sort.ipynb ├── 5. Merge Two Sorted Arrays.ipynb ├── Assignment (8).ipynb └── Searching and Sorting.pdf ├── 09. Strings ├── 1. Introduction to Strings & Immutablity.ipynb ├── 2. Concatenation Of Strings.ipynb ├── 3. Slicing of Strings.ipynb ├── 4. Iterating on Strings.ipynb ├── 5. Comparison Operator on Strings.ipynb ├── 6. Operation on Strings.ipynb ├── 7. Replace Character in Strings.ipynb ├── 8. Count on Strings.ipynb ├── Assignment (9).ipynb └── Strings.pdf ├── 10. Two Dimensional Lists ├── 1. Intro To Two Dimensional Lists.ipynb ├── 2. How Two Dimensional Lists Are Stored.ipynb ├── 3. Jagged Lists.ipynb ├── 4. List Comprehension.ipynb ├── 5. Input of 2D list .ipynb ├── 6. Printing 2D lists Iterating on 2D lists.ipynb ├── 7. Largest Column Sum In 2D List.ipynb ├── Assignment (10).ipynb └── Two Dimensional Lists.pdf ├── 11. Tuples, Dictionary And Sets ├── 01. Tuples.ipynb ├── 02. Tuples Function.ipynb ├── 03. Variable length Input and Output.ipynb ├── 04.Intro Dictionary.ipynb ├── 05. Access & Looping element in Dictionary.ipynb ├── 06. Adding Or Removing Data In Dictionary.ipynb ├── 07. Print All Words With Frequency K.ipynb ├── 08. Sets.ipynb ├── 09. Functions of Sets.ipynb ├── 10. sum of all unique numbers in list.ipynb └── Tuples, Dictionaries and Sets.pdf ├── Certificate └── Coding Ninjas -Introduction to Python.pdf └── README.md /01. Introduction to Python/1. Variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Print Helloworld" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 16, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "HelloWorld\n", 22 | "HelloWorld\n" 23 | ] 24 | } 25 | ], 26 | "source": [ 27 | "print('HelloWorld')\n", 28 | "print('HelloWorld')" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "### Variables" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 11, 41 | "metadata": { 42 | "scrolled": true 43 | }, 44 | "outputs": [ 45 | { 46 | "data": { 47 | "text/plain": [ 48 | "30" 49 | ] 50 | }, 51 | "execution_count": 11, 52 | "metadata": {}, 53 | "output_type": "execute_result" 54 | } 55 | ], 56 | "source": [ 57 | "a =10\n", 58 | "b= 20\n", 59 | "\n", 60 | "a+b" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 1, 66 | "metadata": { 67 | "scrolled": false 68 | }, 69 | "outputs": [ 70 | { 71 | "name": "stdout", 72 | "output_type": "stream", 73 | "text": [ 74 | "1\n", 75 | "2\n", 76 | "3\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "a = int(input())\n", 82 | "b=int(input())\n", 83 | "C = a+b\n", 84 | "print(C)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 20, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "30\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "a = 10\n", 102 | "b = 20\n", 103 | "\n", 104 | "sum = a+b\n", 105 | "print(sum)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "### Variable Check" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 12, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "10\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "_1qa21 = 10\n", 130 | "print(_1qa21)\n", 131 | "#121 = vb" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 17, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "30" 143 | ] 144 | }, 145 | "execution_count": 17, 146 | "metadata": {}, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "a=10\n", 152 | "b=20\n", 153 | "\n", 154 | "a+b" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "### Assigning different types of data to a variable" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 36, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "abcd\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "a = 10\n", 179 | "a = 20\n", 180 | "a = 'abcd'\n", 181 | "print(a)" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 59, 187 | "metadata": {}, 188 | "outputs": [ 189 | { 190 | "name": "stdout", 191 | "output_type": "stream", 192 | "text": [ 193 | "\n", 194 | "\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "a = \"abc\"\n", 200 | "print(type(a))\n", 201 | "a = 10\n", 202 | "print(type(a))" 203 | ] 204 | }, 205 | { 206 | "cell_type": "code", 207 | "execution_count": 8, 208 | "metadata": {}, 209 | "outputs": [ 210 | { 211 | "name": "stdout", 212 | "output_type": "stream", 213 | "text": [ 214 | "abcd\n" 215 | ] 216 | } 217 | ], 218 | "source": [ 219 | "x = 10\n", 220 | "x = \"abcd\"\n", 221 | "print(x)" 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 15, 227 | "metadata": {}, 228 | "outputs": [ 229 | { 230 | "data": { 231 | "text/plain": [ 232 | "int" 233 | ] 234 | }, 235 | "execution_count": 15, 236 | "metadata": {}, 237 | "output_type": "execute_result" 238 | } 239 | ], 240 | "source": [ 241 | "x = \"abcd\"\n", 242 | "x = 10\n", 243 | "type(x)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "markdown", 248 | "metadata": {}, 249 | "source": [ 250 | "### Python Numbers" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 64, 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "140703659731008\n", 263 | "140703659731008\n" 264 | ] 265 | } 266 | ], 267 | "source": [ 268 | "a = 10\n", 269 | "id(a)\n", 270 | "b = a + 2-2\n", 271 | "id(b)\n", 272 | "print(id(a))\n", 273 | "print(id(b))" 274 | ] 275 | } 276 | ], 277 | "metadata": { 278 | "kernelspec": { 279 | "display_name": "Python 3", 280 | "language": "python", 281 | "name": "python3" 282 | }, 283 | "language_info": { 284 | "codemirror_mode": { 285 | "name": "ipython", 286 | "version": 3 287 | }, 288 | "file_extension": ".py", 289 | "mimetype": "text/x-python", 290 | "name": "python", 291 | "nbconvert_exporter": "python", 292 | "pygments_lexer": "ipython3", 293 | "version": "3.8.5" 294 | } 295 | }, 296 | "nbformat": 4, 297 | "nbformat_minor": 4 298 | } 299 | -------------------------------------------------------------------------------- /01. Introduction to Python/2. Python numbers.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Python Numbers" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "23\n", 20 | "3.4\n", 21 | "(4+5j)\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "a1 = 23\n", 27 | "a2 = 3.4\n", 28 | "a3 = 4 + 5j\n", 29 | "print(a1)\n", 30 | "print(a2)\n", 31 | "print(a3)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 10, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "\n", 44 | "\n", 45 | "\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "a1 = 23\n", 51 | "a2 = 3.4\n", 52 | "a3 = 4 + 5j\n", 53 | "print(type(a1))\n", 54 | "print(type(a2))\n", 55 | "print(type(a3))" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 11, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "11" 67 | ] 68 | }, 69 | "execution_count": 11, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "a = 10\n", 76 | "a = a + 1\n", 77 | "a" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 12, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "140703659731008\n", 90 | "140703659731040\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "a = 10\n", 96 | "print(id(a))\n", 97 | "a = a + 1\n", 98 | "print(id(a))" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 9, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "140731464165440\n", 111 | "140731464165440\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "a = 10\n", 117 | "b = 10\n", 118 | "print(id(a))\n", 119 | "print(id(b))" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 30, 125 | "metadata": { 126 | "scrolled": true 127 | }, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "2731900159568\n", 134 | "2731900159056\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "a = 1000\n", 140 | "b = 1000\n", 141 | "print(id(a))\n", 142 | "print(id(b))" 143 | ] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "Python 3", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.8.5" 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 4 167 | } 168 | -------------------------------------------------------------------------------- /01. Introduction to Python/4. Taking inputs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Taking inputs" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "22\n" 22 | ] 23 | }, 24 | { 25 | "data": { 26 | "text/plain": [ 27 | "str" 28 | ] 29 | }, 30 | "execution_count": 1, 31 | "metadata": {}, 32 | "output_type": "execute_result" 33 | } 34 | ], 35 | "source": [ 36 | "a =input()\n", 37 | "a\n", 38 | "type(a)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 3, 44 | "metadata": {}, 45 | "outputs": [ 46 | { 47 | "name": "stdout", 48 | "output_type": "stream", 49 | "text": [ 50 | "23\n" 51 | ] 52 | }, 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "'23'" 57 | ] 58 | }, 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "input()" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 2, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "12\n", 78 | "34\n", 79 | "1234\n", 80 | "\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "a = input() #like \"ab\"+\"cd\" = abcd\n", 86 | "b = input()\n", 87 | "s = a+b\n", 88 | "print(s)\n", 89 | "print(type(a))" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 14, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "data": { 99 | "text/plain": [ 100 | "24" 101 | ] 102 | }, 103 | "execution_count": 14, 104 | "metadata": {}, 105 | "output_type": "execute_result" 106 | } 107 | ], 108 | "source": [ 109 | "#a =input()\n", 110 | "#type(a)\n", 111 | "b=\"24\"\n", 112 | "type(b)\n", 113 | "c = int(b)\n", 114 | "type(c)\n", 115 | "c" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 24, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "data": { 125 | "text/plain": [ 126 | "2" 127 | ] 128 | }, 129 | "execution_count": 24, 130 | "metadata": {}, 131 | "output_type": "execute_result" 132 | } 133 | ], 134 | "source": [ 135 | "b=\"2\"\n", 136 | "c = int(b)\n", 137 | "type(c)\n", 138 | "c" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 20, 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "name": "stdout", 148 | "output_type": "stream", 149 | "text": [ 150 | "22\n" 151 | ] 152 | }, 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "int" 157 | ] 158 | }, 159 | "execution_count": 20, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "a=input()\n", 166 | "b=int(a)\n", 167 | "type(b)" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 21, 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "name": "stdout", 177 | "output_type": "stream", 178 | "text": [ 179 | "22\n" 180 | ] 181 | }, 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "int" 186 | ] 187 | }, 188 | "execution_count": 21, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "a=int(input())\n", 195 | "type(a)" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 22, 201 | "metadata": {}, 202 | "outputs": [ 203 | { 204 | "name": "stdout", 205 | "output_type": "stream", 206 | "text": [ 207 | "23\n", 208 | "34\n", 209 | "57\n", 210 | "\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "a = int(input())\n", 216 | "b = int(input())\n", 217 | "s = a+b\n", 218 | "print(s)\n", 219 | "print(type(a))" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "metadata": {}, 225 | "source": [ 226 | "### float" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 29, 232 | "metadata": { 233 | "scrolled": false 234 | }, 235 | "outputs": [ 236 | { 237 | "name": "stdout", 238 | "output_type": "stream", 239 | "text": [ 240 | "1.3\n" 241 | ] 242 | }, 243 | { 244 | "data": { 245 | "text/plain": [ 246 | "float" 247 | ] 248 | }, 249 | "execution_count": 29, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "a =float(input())\n", 256 | "a\n", 257 | "type(a)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 6, 263 | "metadata": { 264 | "scrolled": false 265 | }, 266 | "outputs": [ 267 | { 268 | "name": "stdout", 269 | "output_type": "stream", 270 | "text": [ 271 | "-2\n", 272 | "5\n", 273 | "2\n", 274 | "-1\n", 275 | "-24\n" 276 | ] 277 | } 278 | ], 279 | "source": [ 280 | "x1 = int(input())\n", 281 | "y1 = int(input())\n", 282 | "x2 = int(input())\n", 283 | "y2 = int(input())\n", 284 | "area = (x2-x1)*(y2-y1)\n", 285 | "print(area)" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 7, 291 | "metadata": { 292 | "scrolled": true 293 | }, 294 | "outputs": [ 295 | { 296 | "name": "stdout", 297 | "output_type": "stream", 298 | "text": [ 299 | "10\n", 300 | "4\n", 301 | "10000\n" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "X = int(input())\n", 307 | "N = int(input())\n", 308 | "print(X**N)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 8, 314 | "metadata": { 315 | "scrolled": true 316 | }, 317 | "outputs": [ 318 | { 319 | "name": "stdout", 320 | "output_type": "stream", 321 | "text": [ 322 | "10\n", 323 | "20\n", 324 | "30\n", 325 | "20.0\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "x = int(input())\n", 331 | "y = int(input())\n", 332 | "z = int(input())\n", 333 | "a = (x + y + z)/3 #a= Average\n", 334 | "print(a)" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 2, 340 | "metadata": { 341 | "scrolled": true 342 | }, 343 | "outputs": [ 344 | { 345 | "name": "stdout", 346 | "output_type": "stream", 347 | "text": [ 348 | "10\n", 349 | "20\n", 350 | "30\n", 351 | "60\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "p= int(input())\n", 357 | "r = int(input())\n", 358 | "t = int(input())\n", 359 | "\n", 360 | "Si = (p*r*t)//100\n", 361 | "\n", 362 | "print(Si)" 363 | ] 364 | } 365 | ], 366 | "metadata": { 367 | "kernelspec": { 368 | "display_name": "Python 3", 369 | "language": "python", 370 | "name": "python3" 371 | }, 372 | "language_info": { 373 | "codemirror_mode": { 374 | "name": "ipython", 375 | "version": 3 376 | }, 377 | "file_extension": ".py", 378 | "mimetype": "text/x-python", 379 | "name": "python", 380 | "nbconvert_exporter": "python", 381 | "pygments_lexer": "ipython3", 382 | "version": "3.8.5" 383 | } 384 | }, 385 | "nbformat": 4, 386 | "nbformat_minor": 4 387 | } 388 | -------------------------------------------------------------------------------- /01. Introduction to Python/Assignment (1).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Find average Marks" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "3\n", 22 | "4\n", 23 | "6\n", 24 | "4.333333333333333\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "a = int(input())\n", 30 | "b = int(input())\n", 31 | "c = int(input())\n", 32 | "\n", 33 | "Average = (a+b+c)/3\n", 34 | "\n", 35 | "print(Average)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "# Find X raised to power N\n" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 2, 48 | "metadata": { 49 | "scrolled": true 50 | }, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "10\n", 57 | "4\n", 58 | "10000\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "X = int(input())\n", 64 | "Y = int(input())\n", 65 | "\n", 66 | "Power = X**Y\n", 67 | "\n", 68 | "print(Power)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "# Arithmetic Progression\n" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 3, 81 | "metadata": { 82 | "scrolled": true 83 | }, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "1\n", 90 | "3\n", 91 | "5\n", 92 | "2\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "a = int(input())\n", 98 | "b = int(input())\n", 99 | "c = int(input())\n", 100 | "\n", 101 | "Common_Difference = c-b\n", 102 | "\n", 103 | "print(Common_Difference)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "# Rectangular Area\n" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 4, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "1\n", 123 | "1\n", 124 | "3\n", 125 | "3\n", 126 | "4\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "x1 = int(input())\n", 132 | "y1 = int(input())\n", 133 | "x2 = int(input())\n", 134 | "y2 = int(input())\n", 135 | "area = (x2-x1)*(y2-y1)\n", 136 | "print(area)" 137 | ] 138 | } 139 | ], 140 | "metadata": { 141 | "kernelspec": { 142 | "display_name": "Python 3", 143 | "language": "python", 144 | "name": "python3" 145 | }, 146 | "language_info": { 147 | "codemirror_mode": { 148 | "name": "ipython", 149 | "version": 3 150 | }, 151 | "file_extension": ".py", 152 | "mimetype": "text/x-python", 153 | "name": "python", 154 | "nbconvert_exporter": "python", 155 | "pygments_lexer": "ipython3", 156 | "version": "3.8.5" 157 | } 158 | }, 159 | "nbformat": 4, 160 | "nbformat_minor": 4 161 | } 162 | -------------------------------------------------------------------------------- /01. Introduction to Python/Introduction to Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/01. Introduction to Python/Introduction to Python.pdf -------------------------------------------------------------------------------- /02. Conditionals and Loops/1. Operators & Else If.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Boolean" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 4, 13 | "metadata": { 14 | "scrolled": false 15 | }, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "bool" 21 | ] 22 | }, 23 | "execution_count": 4, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "a = True\n", 30 | "b = False\n", 31 | "c = True\n", 32 | "type(c)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "### Relational Operator" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 6, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "False\n", 52 | "False\n", 53 | "True\n", 54 | "True\n", 55 | "False\n", 56 | "True\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "a=10\n", 62 | "b=20\n", 63 | "print(a>b)\n", 64 | "print(a>=b)\n", 65 | "print(a10\n", 99 | "c2=b>10\n", 100 | "r1=c1 and c2\n", 101 | "r2=c1 or c2\n", 102 | "r3= not(c1)\n", 103 | "print(r1)\n", 104 | "print(r2)\n", 105 | "print(r3)" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "### IF ELSE" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 34, 118 | "metadata": { 119 | "scrolled": true 120 | }, 121 | "outputs": [ 122 | { 123 | "name": "stdout", 124 | "output_type": "stream", 125 | "text": [ 126 | "im if\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "a = True\n", 132 | "if a:\n", 133 | " print('im if')\n", 134 | "else:\n", 135 | " print('im else')" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 37, 141 | "metadata": { 142 | "scrolled": true 143 | }, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "5\n", 150 | "n is odd\n" 151 | ] 152 | } 153 | ], 154 | "source": [ 155 | "#check number is even or odd\n", 156 | "n=int(input())\n", 157 | "r=n%2\n", 158 | "is_even=(r==0)\n", 159 | "if is_even:\n", 160 | " print(\"n is even\")\n", 161 | "else:\n", 162 | " print('n is odd')" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 40, 168 | "metadata": { 169 | "scrolled": true 170 | }, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "5\n", 177 | "n is odd\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "#check number is even or odd\n", 183 | "n=int(input())\n", 184 | "is_even=(n%2==0)\n", 185 | "if is_even:\n", 186 | " print(\"n is even\")\n", 187 | "else:\n", 188 | " print('n is odd')" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": 1, 194 | "metadata": { 195 | "scrolled": false 196 | }, 197 | "outputs": [ 198 | { 199 | "name": "stdout", 200 | "output_type": "stream", 201 | "text": [ 202 | "12\n", 203 | "n is even\n" 204 | ] 205 | } 206 | ], 207 | "source": [ 208 | "#check number is even or odd\n", 209 | "n=int(input())\n", 210 | "if n%2==0:\n", 211 | " print(\"n is even\")\n", 212 | "else:\n", 213 | " print('n is odd')" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 68, 219 | "metadata": { 220 | "scrolled": true 221 | }, 222 | "outputs": [ 223 | { 224 | "name": "stdout", 225 | "output_type": "stream", 226 | "text": [ 227 | "-1\n", 228 | "negative\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "#n is -ive or +ive\n", 234 | "n=int(input())\n", 235 | "if n>0:\n", 236 | " print('positive')\n", 237 | "elif n<0:\n", 238 | " print('negative')\n", 239 | "else:\n", 240 | " print(\"zero\")" 241 | ] 242 | } 243 | ], 244 | "metadata": { 245 | "kernelspec": { 246 | "display_name": "Python 3", 247 | "language": "python", 248 | "name": "python3" 249 | }, 250 | "language_info": { 251 | "codemirror_mode": { 252 | "name": "ipython", 253 | "version": 3 254 | }, 255 | "file_extension": ".py", 256 | "mimetype": "text/x-python", 257 | "name": "python", 258 | "nbconvert_exporter": "python", 259 | "pygments_lexer": "ipython3", 260 | "version": "3.8.5" 261 | } 262 | }, 263 | "nbformat": 4, 264 | "nbformat_minor": 4 265 | } 266 | -------------------------------------------------------------------------------- /02. Conditionals and Loops/2. Nested Conditionals & While Loop.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### ELIF" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 10, 13 | "metadata": { 14 | "scrolled": false 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "7\n", 22 | "8\n", 23 | "9\n", 24 | "9\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "#FINDING LARGEST\n", 30 | "a=int(input())\n", 31 | "b=int(input())\n", 32 | "c=int(input())\n", 33 | "\n", 34 | "if a>=b and a>=c:\n", 35 | " print(a)\n", 36 | "elif b>=a and b>=c:\n", 37 | " print(b)\n", 38 | "else:\n", 39 | " print(c)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "### Nested IF ELSE" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 6, 52 | "metadata": { 53 | "scrolled": false 54 | }, 55 | "outputs": [ 56 | { 57 | "name": "stdout", 58 | "output_type": "stream", 59 | "text": [ 60 | "0\n", 61 | "n is even\n", 62 | "n is zero\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "#check number is even or odd\n", 68 | "n=int(input())\n", 69 | "if n%2==0:\n", 70 | " print(\"n is even\")\n", 71 | " if n==0:\n", 72 | " print(\"n is zero\")\n", 73 | "else:\n", 74 | " print('n is odd')" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 6, 80 | "metadata": { 81 | "scrolled": false 82 | }, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "1\n", 89 | "1\n", 90 | "3\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "#if n and m is even print1\n", 96 | "# if n and m is odd print2\n", 97 | "# if n is odd\n", 98 | "n=int(input())\n", 99 | "m=int(input())\n", 100 | "\n", 101 | "if n%2==0:\n", 102 | " if m%2==0:\n", 103 | " print(1)\n", 104 | " else:\n", 105 | " print(2)\n", 106 | "else:\n", 107 | " print(3)" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 25, 113 | "metadata": { 114 | "scrolled": false 115 | }, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "B\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "if True or True:\n", 127 | " if False and True or False:\n", 128 | " print('A')\n", 129 | " elif False and False or True and True:\n", 130 | " print('B')\n", 131 | " else:\n", 132 | " print('C')\n", 133 | "else:\n", 134 | " print('D')" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "### While Loop" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 17, 147 | "metadata": { 148 | "scrolled": true 149 | }, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "10\n", 156 | "1\n", 157 | "1\n", 158 | "1\n", 159 | "1\n", 160 | "1\n", 161 | "1\n", 162 | "1\n", 163 | "1\n", 164 | "1\n", 165 | "1\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "n = int(input())\n", 171 | "count = 1\n", 172 | "while count <=n:\n", 173 | " print(1)\n", 174 | " count = count+1" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 5, 180 | "metadata": { 181 | "scrolled": true 182 | }, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "10\n", 189 | "1\n", 190 | "2\n", 191 | "3\n", 192 | "4\n", 193 | "5\n", 194 | "6\n", 195 | "7\n", 196 | "8\n", 197 | "9\n", 198 | "10\n" 199 | ] 200 | } 201 | ], 202 | "source": [ 203 | "#first n natural numbers\n", 204 | "n = int(input())\n", 205 | "i = 1\n", 206 | "while i<=n:\n", 207 | " print(i)\n", 208 | " i = i+1" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 23, 214 | "metadata": { 215 | "scrolled": false 216 | }, 217 | "outputs": [ 218 | { 219 | "name": "stdout", 220 | "output_type": "stream", 221 | "text": [ 222 | "10\n", 223 | "55\n" 224 | ] 225 | } 226 | ], 227 | "source": [ 228 | "N = int(input())\n", 229 | "sum = 0\n", 230 | "i = 1\n", 231 | "\n", 232 | "while i <= n:\n", 233 | " sum = sum + i\n", 234 | " i = i+1\n", 235 | "\n", 236 | "print(sum)" 237 | ] 238 | } 239 | ], 240 | "metadata": { 241 | "kernelspec": { 242 | "display_name": "Python 3", 243 | "language": "python", 244 | "name": "python3" 245 | }, 246 | "language_info": { 247 | "codemirror_mode": { 248 | "name": "ipython", 249 | "version": 3 250 | }, 251 | "file_extension": ".py", 252 | "mimetype": "text/x-python", 253 | "name": "python", 254 | "nbconvert_exporter": "python", 255 | "pygments_lexer": "ipython3", 256 | "version": "3.8.5" 257 | } 258 | }, 259 | "nbformat": 4, 260 | "nbformat_minor": 4 261 | } 262 | -------------------------------------------------------------------------------- /02. Conditionals and Loops/Conditionals and Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/02. Conditionals and Loops/Conditionals and Loops.pdf -------------------------------------------------------------------------------- /03. Patterns 1/1. Patterns.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Patterns " 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "****\n", 15 | "**** \n", 16 | "****\n", 17 | "****" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 4, 23 | "metadata": { 24 | "scrolled": false 25 | }, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "4\n", 32 | "****\n", 33 | "****\n", 34 | "****\n", 35 | "****\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "n = int(input())\n", 41 | "i = 1\n", 42 | "while i <=n:\n", 43 | " j = 1 \n", 44 | " while j <=n:\n", 45 | " print('*',end ='')\n", 46 | " j = j+1\n", 47 | " print()\n", 48 | " i = i+1" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "4444\n", 56 | "4444\n", 57 | "4444\n", 58 | "4444" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 12, 64 | "metadata": { 65 | "scrolled": true 66 | }, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "4\n", 73 | "4444\n", 74 | "4444\n", 75 | "4444\n", 76 | "4444\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "n=int(input())\n", 82 | "i=1\n", 83 | "while i <=n:\n", 84 | " j=1\n", 85 | " while j<=n:\n", 86 | " print(n,end=\"\")\n", 87 | " j=j+1\n", 88 | " print()\n", 89 | " i=i+1" 90 | ] 91 | } 92 | ], 93 | "metadata": { 94 | "kernelspec": { 95 | "display_name": "Python 3", 96 | "language": "python", 97 | "name": "python3" 98 | }, 99 | "language_info": { 100 | "codemirror_mode": { 101 | "name": "ipython", 102 | "version": 3 103 | }, 104 | "file_extension": ".py", 105 | "mimetype": "text/x-python", 106 | "name": "python", 107 | "nbconvert_exporter": "python", 108 | "pygments_lexer": "ipython3", 109 | "version": "3.8.5" 110 | } 111 | }, 112 | "nbformat": 4, 113 | "nbformat_minor": 4 114 | } 115 | -------------------------------------------------------------------------------- /03. Patterns 1/2. Square Patterns.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "#### Square Patterns" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "1111\n", 15 | "2222\n", 16 | "3333\n", 17 | "4444" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 2, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "4\n", 30 | "1111\n", 31 | "2222\n", 32 | "3333\n", 33 | "4444\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "n = int(input())\n", 39 | "i = 1\n", 40 | "while n>=i:\n", 41 | " j = 1\n", 42 | " while j<=n:\n", 43 | " print(i,end='')\n", 44 | " j = j+1\n", 45 | " print()\n", 46 | " i = i + 1" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "1234\n", 54 | "1234\n", 55 | "1234\n", 56 | "1234" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 2, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "4\n", 69 | "1234\n", 70 | "1234\n", 71 | "1234\n", 72 | "1234\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "n = int(input())\n", 78 | "i = 1\n", 79 | "while n>=i:\n", 80 | " j = 1\n", 81 | " while j<=n:\n", 82 | " print(j,end='')\n", 83 | " j = j+1\n", 84 | " print()\n", 85 | " i = i + 1" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "4321\n", 93 | "4321\n", 94 | "4321\n", 95 | "4321" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 4, 101 | "metadata": { 102 | "scrolled": true 103 | }, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "4\n", 110 | "4321\n", 111 | "4321\n", 112 | "4321\n", 113 | "4321\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "n = int(input())\n", 119 | "i = 1\n", 120 | "while n>=i:\n", 121 | " j = 1\n", 122 | " while j<=n:\n", 123 | " print(n-j+1,end='')\n", 124 | " j = j+1\n", 125 | " print()\n", 126 | " i = i + 1" 127 | ] 128 | } 129 | ], 130 | "metadata": { 131 | "kernelspec": { 132 | "display_name": "Python 3", 133 | "language": "python", 134 | "name": "python3" 135 | }, 136 | "language_info": { 137 | "codemirror_mode": { 138 | "name": "ipython", 139 | "version": 3 140 | }, 141 | "file_extension": ".py", 142 | "mimetype": "text/x-python", 143 | "name": "python", 144 | "nbconvert_exporter": "python", 145 | "pygments_lexer": "ipython3", 146 | "version": "3.8.5" 147 | } 148 | }, 149 | "nbformat": 4, 150 | "nbformat_minor": 4 151 | } 152 | -------------------------------------------------------------------------------- /03. Patterns 1/4. Character Patterns.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Character Patterns" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "65" 21 | ] 22 | }, 23 | "execution_count": 1, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "ord('A')" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 4, 35 | "metadata": { 36 | "scrolled": true 37 | }, 38 | "outputs": [ 39 | { 40 | "data": { 41 | "text/plain": [ 42 | "66" 43 | ] 44 | }, 45 | "execution_count": 4, 46 | "metadata": {}, 47 | "output_type": "execute_result" 48 | } 49 | ], 50 | "source": [ 51 | "ord('B')" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 8, 57 | "metadata": { 58 | "scrolled": false 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "A\n", 66 | "B\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "print(chr(65))\n", 72 | "print(chr(66))" 73 | ] 74 | }, 75 | { 76 | "cell_type": "raw", 77 | "metadata": {}, 78 | "source": [ 79 | "Print Kth character " 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 10, 85 | "metadata": { 86 | "scrolled": false 87 | }, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "4\n" 94 | ] 95 | }, 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "'D'" 100 | ] 101 | }, 102 | "execution_count": 10, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "k = int(input())\n", 109 | "x = ord('A')\n", 110 | "asciiTarget = x+k-1\n", 111 | "targetChar = chr(asciiTarget)\n", 112 | "targetChar" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "ABCD\n", 120 | "ABCD\n", 121 | "ABCD\n", 122 | "ABCD" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 16, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "name": "stdout", 132 | "output_type": "stream", 133 | "text": [ 134 | "4\n", 135 | "ABCD\n", 136 | "ABCD\n", 137 | "ABCD\n", 138 | "ABCD\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "n = int(input())\n", 144 | "i = 1\n", 145 | "while n>=i:\n", 146 | " j = 1\n", 147 | " while j<=n:\n", 148 | " charP =chr(ord('A') +j-1)\n", 149 | " print(charP,end='')\n", 150 | " j = j+1\n", 151 | " print()\n", 152 | " i = i + 1" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 1, 163 | "metadata": { 164 | "scrolled": false 165 | }, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "4\n", 172 | "ABCD\n", 173 | "BCDE\n", 174 | "CDEF\n", 175 | "DEFG\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "n = int(input())\n", 181 | "i = 1\n", 182 | "while n>=i:\n", 183 | " j = 1\n", 184 | " start_char = chr(ord('A')+i-1)\n", 185 | " while j<=n:\n", 186 | " charP =chr(ord(start_char) +j-1)\n", 187 | " print(charP,end='')\n", 188 | " j = j+1\n", 189 | " print()\n", 190 | " i = i + 1" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": null, 196 | "metadata": {}, 197 | "outputs": [], 198 | "source": [ 199 | "new" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 1, 205 | "metadata": { 206 | "scrolled": true 207 | }, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "4\n", 214 | "A\n", 215 | "BB\n", 216 | "CCC\n", 217 | "DDDD\n" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "n = int(input())\n", 223 | "\n", 224 | "i = 1\n", 225 | "\n", 226 | "while i <= n:\n", 227 | " \n", 228 | " char = chr(ord('A') + i - 1)\n", 229 | " \n", 230 | " j = 1\n", 231 | " \n", 232 | " while j <= i:\n", 233 | " print(char, end=\"\")\n", 234 | " j += 1\n", 235 | " \n", 236 | " print()\n", 237 | " i +=1" 238 | ] 239 | } 240 | ], 241 | "metadata": { 242 | "kernelspec": { 243 | "display_name": "Python 3", 244 | "language": "python", 245 | "name": "python3" 246 | }, 247 | "language_info": { 248 | "codemirror_mode": { 249 | "name": "ipython", 250 | "version": 3 251 | }, 252 | "file_extension": ".py", 253 | "mimetype": "text/x-python", 254 | "name": "python", 255 | "nbconvert_exporter": "python", 256 | "pygments_lexer": "ipython3", 257 | "version": "3.8.5" 258 | } 259 | }, 260 | "nbformat": 4, 261 | "nbformat_minor": 4 262 | } 263 | -------------------------------------------------------------------------------- /03. Patterns 1/Patterns 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/03. Patterns 1/Patterns 1.pdf -------------------------------------------------------------------------------- /04. Patterns 2/1. Inverted triangle.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "****\n", 8 | "***\n", 9 | "**\n", 10 | "*" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 9, 16 | "metadata": { 17 | "scrolled": true 18 | }, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "4\n", 25 | "****\n", 26 | "***\n", 27 | "**\n", 28 | "*\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "n = int(input())\n", 34 | "i = 1\n", 35 | "while i<=n:\n", 36 | " j = 1\n", 37 | " while j <= n-i+1:\n", 38 | " print('*',end='') \n", 39 | " j = j +1\n", 40 | " print() \n", 41 | " i = i+1" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 5, 47 | "metadata": { 48 | "scrolled": true 49 | }, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "4\n", 56 | "1111\n", 57 | "000\n", 58 | "11\n", 59 | "0\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "n = int(input())\n", 65 | "i = 1\n", 66 | "while i <= n:\n", 67 | " j =1\n", 68 | " while j<= n-i+1:\n", 69 | " print(i%2,end='')\n", 70 | " j = j+1\n", 71 | " print()\n", 72 | " i = i + 1" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 26, 78 | "metadata": { 79 | "scrolled": true 80 | }, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "4\n", 87 | "A\n", 88 | "BB\n", 89 | "CCC\n", 90 | "DDDD\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "n = int(input())\n", 96 | "\n", 97 | "i = 1\n", 98 | "\n", 99 | "while i <= n:\n", 100 | " \n", 101 | " char = chr(ord('A') + i - 1)\n", 102 | " \n", 103 | " j = 1\n", 104 | " \n", 105 | " while j <= i:\n", 106 | " print(char, end=\"\")\n", 107 | " j += 1\n", 108 | " \n", 109 | " print()\n", 110 | " i +=1" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 1, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "4\n", 123 | "1\n", 124 | "11\n", 125 | "121\n", 126 | "1221\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "n=int(input())\n", 132 | "i=1\n", 133 | "while i<=n:\n", 134 | " j=1\n", 135 | " while j<=i:\n", 136 | " if i==1:\n", 137 | " print('1',end='')\n", 138 | " elif j==1 or i==j:\n", 139 | " print('1',end='')\n", 140 | " else:\n", 141 | " print('2',end='')\n", 142 | " j=j+1\n", 143 | " print()\n", 144 | " i=i+1" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 3, 150 | "metadata": { 151 | "scrolled": true 152 | }, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "4\n", 159 | "D\n", 160 | "CD\n", 161 | "BCD\n", 162 | "ABCD\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "n = int(input())\n", 168 | "i = n\n", 169 | "while i >= 1:\n", 170 | " j = i\n", 171 | " while j<=n:\n", 172 | " print(chr(ord(\"A\")+j-1),end=\"\")\n", 173 | " j = j + 1\n", 174 | " print()\n", 175 | " i = i - 1" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 1, 181 | "metadata": { 182 | "scrolled": true 183 | }, 184 | "outputs": [ 185 | { 186 | "name": "stdout", 187 | "output_type": "stream", 188 | "text": [ 189 | "4\n", 190 | "1234\n", 191 | "123\n", 192 | "12\n", 193 | "1\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "n = int(input())\n", 199 | "i = 1\n", 200 | "while i<=n:\n", 201 | " j = 1\n", 202 | " p =1\n", 203 | " while j <= n-i+1:\n", 204 | " print(p,end='') \n", 205 | " j = j +1\n", 206 | " p =p+1\n", 207 | " print() \n", 208 | " i = i+1" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 18, 214 | "metadata": { 215 | "scrolled": true 216 | }, 217 | "outputs": [ 218 | { 219 | "name": "stdout", 220 | "output_type": "stream", 221 | "text": [ 222 | "5\n", 223 | "1 2 3 4 5 \n", 224 | "11 12 13 14 15 \n", 225 | "21 22 23 24 25 \n", 226 | "16 17 18 19 20 \n", 227 | "6 7 8 9 10 \n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "n=int(input())\n", 233 | "s=1\n", 234 | "for i in range (1,n+1):\n", 235 | " for j in range(s,s+n):\n", 236 | " print(j ,end=\" \")\n", 237 | " print()\n", 238 | " if (i==((n+1)//2)):\n", 239 | " if n%2!=0:\n", 240 | " s=n*(n-2)+1\n", 241 | " else:\n", 242 | " s=n*(n-1)+1\n", 243 | " continue\n", 244 | " if (i>(n+1)//2):\n", 245 | " s=s-2*n\n", 246 | " else:\n", 247 | " s=s+2*n" 248 | ] 249 | } 250 | ], 251 | "metadata": { 252 | "kernelspec": { 253 | "display_name": "Python 3", 254 | "language": "python", 255 | "name": "python3" 256 | }, 257 | "language_info": { 258 | "codemirror_mode": { 259 | "name": "ipython", 260 | "version": 3 261 | }, 262 | "file_extension": ".py", 263 | "mimetype": "text/x-python", 264 | "name": "python", 265 | "nbconvert_exporter": "python", 266 | "pygments_lexer": "ipython3", 267 | "version": "3.8.5" 268 | } 269 | }, 270 | "nbformat": 4, 271 | "nbformat_minor": 4 272 | } 273 | -------------------------------------------------------------------------------- /04. Patterns 2/Patterns 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/04. Patterns 2/Patterns 2.pdf -------------------------------------------------------------------------------- /05. More on Loops/1. forloop.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "a\n", 15 | "b\n", 16 | "c\n", 17 | "d\n" 18 | ] 19 | } 20 | ], 21 | "source": [ 22 | "s = 'abcd'\n", 23 | "for a in s:\n", 24 | " print(a)" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 7, 30 | "metadata": { 31 | "scrolled": true 32 | }, 33 | "outputs": [ 34 | { 35 | "name": "stdout", 36 | "output_type": "stream", 37 | "text": [ 38 | "4\n", 39 | "1\n", 40 | "2\n", 41 | "3\n", 42 | "4\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "#print n numbers from 1 to n.\n", 48 | "#with 3 value\n", 49 | "n = int(input())\n", 50 | "for i in range(1,n+1,1):\n", 51 | " print(i)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 10, 57 | "metadata": { 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "4\n", 66 | "0\n", 67 | "1\n", 68 | "2\n", 69 | "3\n", 70 | "4\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "#print n numbers from 1 to n.\n", 76 | "#with 1 value\n", 77 | "#start is default as 0 & stride(step) is 1. \n", 78 | "n = int(input())\n", 79 | "for i in range(n+1):\n", 80 | " print(i)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 12, 86 | "metadata": { 87 | "scrolled": true 88 | }, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "4\n", 95 | "1\n", 96 | "2\n", 97 | "3\n", 98 | "4\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "#print n numbers from 1 to n.\n", 104 | "#with 2 value\n", 105 | "#1st value is start ,2nd value is stop & default stride(step) as 1. \n", 106 | "n = int(input())\n", 107 | "for i in range(1,n+1):\n", 108 | " print(i)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 16, 114 | "metadata": { 115 | "scrolled": false 116 | }, 117 | "outputs": [ 118 | { 119 | "name": "stdout", 120 | "output_type": "stream", 121 | "text": [ 122 | "4\n", 123 | "4\n", 124 | "3\n", 125 | "2\n", 126 | "1\n" 127 | ] 128 | } 129 | ], 130 | "source": [ 131 | "#opposite numbers.\n", 132 | "n = int(input())\n", 133 | "for i in range (n,0,-1):\n", 134 | " print(i)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 17, 140 | "metadata": { 141 | "scrolled": true 142 | }, 143 | "outputs": [ 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "1 3 " 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "for i in range(1,5,2):\n", 154 | " print(i,end=' ')" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 18, 160 | "metadata": { 161 | "scrolled": false 162 | }, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "0 1 2 3 4 " 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "for i in range(5):\n", 174 | " print(i,end= ' ')" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "### multiple of 3" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 10, 187 | "metadata": { 188 | "scrolled": false 189 | }, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "1\n", 196 | "10\n", 197 | "3\n", 198 | "6\n", 199 | "9\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "a = int(input())\n", 205 | "b = int(input())\n", 206 | "\n", 207 | "\n", 208 | "for i in range(a,b+1,1):\n", 209 | " if i%3==0:\n", 210 | " print(i)" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 14, 216 | "metadata": { 217 | "scrolled": true 218 | }, 219 | "outputs": [ 220 | { 221 | "name": "stdout", 222 | "output_type": "stream", 223 | "text": [ 224 | "7\n", 225 | "35\n", 226 | "9\n", 227 | "12\n", 228 | "15\n", 229 | "18\n", 230 | "21\n", 231 | "24\n", 232 | "27\n", 233 | "30\n", 234 | "33\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "a = int(input())\n", 240 | "b = int(input())\n", 241 | "\n", 242 | "if a%3==0:\n", 243 | " s = a\n", 244 | "elif a%3==1:\n", 245 | " s = a+2\n", 246 | "else:\n", 247 | " s = a+1\n", 248 | "for i in range(s,b+1,3):\n", 249 | " print(i)" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 2, 255 | "metadata": { 256 | "scrolled": true 257 | }, 258 | "outputs": [ 259 | { 260 | "name": "stdout", 261 | "output_type": "stream", 262 | "text": [ 263 | "7\n", 264 | "prime\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "#prime no. \n", 270 | "n = int(input())\n", 271 | "flag = False\n", 272 | "for d in range(2,n,1):\n", 273 | " if n%d ==0:\n", 274 | " flag = True\n", 275 | " \n", 276 | "if flag:\n", 277 | " print('not prime')\n", 278 | "else:\n", 279 | " print('prime')" 280 | ] 281 | }, 282 | { 283 | "cell_type": "markdown", 284 | "metadata": {}, 285 | "source": [ 286 | "### patterns" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 2, 292 | "metadata": { 293 | "scrolled": true 294 | }, 295 | "outputs": [ 296 | { 297 | "name": "stdout", 298 | "output_type": "stream", 299 | "text": [ 300 | "4\n", 301 | " 1\n", 302 | " 232\n", 303 | " 34543\n", 304 | "4567654\n" 305 | ] 306 | } 307 | ], 308 | "source": [ 309 | "n = int(input())\n", 310 | "for i in range(1,n+1,1):\n", 311 | " for s in range(n-i):\n", 312 | " print(' ',end='')\n", 313 | " for j in range(i,2*i,1):\n", 314 | " print(j,end=\"\")\n", 315 | " for j in range(2*i-2,i-1,-1):\n", 316 | " print(j,end=\"\")\n", 317 | " print() " 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 1, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "name": "stdout", 327 | "output_type": "stream", 328 | "text": [ 329 | "3\n", 330 | " 1\n", 331 | " 232\n", 332 | "34543\n" 333 | ] 334 | } 335 | ], 336 | "source": [ 337 | "n = int(input())\n", 338 | "for i in range(1,n+1,1):\n", 339 | " for s in range(n-i):\n", 340 | " print(' ',end='')\n", 341 | " for j in range(i,2*i,1):\n", 342 | " print(j,end=\"\")\n", 343 | " for j in range(2*i-2,i-1,-1):\n", 344 | " print(j,end=\"\")\n", 345 | " print() " 346 | ] 347 | } 348 | ], 349 | "metadata": { 350 | "kernelspec": { 351 | "display_name": "Python 3", 352 | "language": "python", 353 | "name": "python3" 354 | }, 355 | "language_info": { 356 | "codemirror_mode": { 357 | "name": "ipython", 358 | "version": 3 359 | }, 360 | "file_extension": ".py", 361 | "mimetype": "text/x-python", 362 | "name": "python", 363 | "nbconvert_exporter": "python", 364 | "pygments_lexer": "ipython3", 365 | "version": "3.8.5" 366 | } 367 | }, 368 | "nbformat": 4, 369 | "nbformat_minor": 4 370 | } 371 | -------------------------------------------------------------------------------- /05. More on Loops/Assignment (5).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Binary Pattern" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "4\n", 20 | "1111\n", 21 | "000\n", 22 | "11\n", 23 | "0\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "n = int(input())\n", 29 | "i = 1\n", 30 | "while i <= n:\n", 31 | " j =1\n", 32 | " while j<= n-i+1:\n", 33 | " print(i%2,end='')\n", 34 | " j = j+1\n", 35 | " print()\n", 36 | " i = i + 1" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "# Print Number Pyramid" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "name": "stdout", 53 | "output_type": "stream", 54 | "text": [ 55 | "6\n", 56 | "123456\n", 57 | " 23456\n", 58 | " 3456\n", 59 | " 456\n", 60 | " 56\n", 61 | " 6\n", 62 | " 56\n", 63 | " 456\n", 64 | " 3456\n", 65 | " 23456\n", 66 | "123456\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "n = int(input())\n", 72 | "for i in range(1,n+1):\n", 73 | " count=1\n", 74 | " for j in range (1,i):\n", 75 | " print(' ',end='')\n", 76 | " count +=1\n", 77 | " num = i\n", 78 | " for j in range(count,n+1):\n", 79 | " print(num,end='')\n", 80 | " num +=1\n", 81 | " print()\n", 82 | "for i in range(n-1,0,-1):\n", 83 | " count =1\n", 84 | " for j in range(1,i):\n", 85 | " print(\" \",end='')\n", 86 | " count +=1\n", 87 | " num =i\n", 88 | " for j in range(count,n+1):\n", 89 | " print(num,end=\"\")\n", 90 | " num +=1\n", 91 | " print()" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "# Diamond of Stars" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 4, 104 | "metadata": {}, 105 | "outputs": [ 106 | { 107 | "name": "stdout", 108 | "output_type": "stream", 109 | "text": [ 110 | "5\n", 111 | " *\n", 112 | " ***\n", 113 | "*****\n", 114 | " ***\n", 115 | " *\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "n=int(input())\n", 121 | "n1=(n+1)//2\n", 122 | "n2=n1-1\n", 123 | "i=1\n", 124 | "while(i<=n1):\n", 125 | " a=1\n", 126 | " while(a<=n1-i):\n", 127 | " print(\" \",end=\"\")\n", 128 | " a=a+1\n", 129 | " b=1\n", 130 | " while(b<=2*i-1):\n", 131 | " print('*',end=\"\")\n", 132 | " b=b+1\n", 133 | " print()\n", 134 | " i=i+1\n", 135 | "i=n2\n", 136 | "while(i>=1):\n", 137 | " a=1\n", 138 | " while(a<=n2 - i +1):\n", 139 | " print(\" \",end='')\n", 140 | " a = a+1\n", 141 | " j=1\n", 142 | " while(j<=2*i-1):\n", 143 | " print('*',end=\"\")\n", 144 | " j=j+1\n", 145 | " print()\n", 146 | " i = i-1" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "# Rectangular numbers" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": 5, 159 | "metadata": {}, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "4\n", 166 | "4444444\n", 167 | "4333334\n", 168 | "4322234\n", 169 | "4321234\n", 170 | "4322234\n", 171 | "4333334\n", 172 | "4444444\n" 173 | ] 174 | } 175 | ], 176 | "source": [ 177 | "n=int(input())\n", 178 | "i=n\n", 179 | "while i>=1:\n", 180 | " j=n\n", 181 | " while j>i:\n", 182 | " print(j,end='')\n", 183 | " j=j-1\n", 184 | " j=1\n", 185 | " while j<=2*i-1:\n", 186 | " print(i,end='')\n", 187 | " j=j+1\n", 188 | " j=i+1\n", 189 | " while j<=n:\n", 190 | " print(j,end='')\n", 191 | " j=j+1\n", 192 | " \n", 193 | " print()\n", 194 | " i=i-1\n", 195 | "i=1\n", 196 | "while ii:\n", 199 | " print(j,end='')\n", 200 | " j=j-1\n", 201 | " j=1\n", 202 | " while j<=2*i-1:\n", 203 | " print(i+1,end='')\n", 204 | " j=j+1\n", 205 | " j=i+1\n", 206 | " while j<=n:\n", 207 | " print(j,end='')\n", 208 | " j=j+1\n", 209 | " \n", 210 | " print()\n", 211 | " i=i+1" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "# Print the pattern" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 6, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "name": "stdout", 228 | "output_type": "stream", 229 | "text": [ 230 | "4\n", 231 | "1 2 3 4 \n", 232 | "9 10 11 12 \n", 233 | "13 14 15 16 \n", 234 | "5 6 7 8 \n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "n=int(input())\n", 240 | "s=1\n", 241 | "for i in range (1,n+1):\n", 242 | " for j in range(s,s+n):\n", 243 | " print(j ,end=\" \")\n", 244 | " print()\n", 245 | " if (i==((n+1)//2)):\n", 246 | " if n%2!=0:\n", 247 | " s=n*(n-2)+1\n", 248 | " else:\n", 249 | " s=n*(n-1)+1\n", 250 | " continue\n", 251 | " if (i>(n+1)//2):\n", 252 | " s=s-2*n\n", 253 | " else:\n", 254 | " s=s+2*n" 255 | ] 256 | } 257 | ], 258 | "metadata": { 259 | "kernelspec": { 260 | "display_name": "Python 3", 261 | "language": "python", 262 | "name": "python3" 263 | }, 264 | "language_info": { 265 | "codemirror_mode": { 266 | "name": "ipython", 267 | "version": 3 268 | }, 269 | "file_extension": ".py", 270 | "mimetype": "text/x-python", 271 | "name": "python", 272 | "nbconvert_exporter": "python", 273 | "pygments_lexer": "ipython3", 274 | "version": "3.8.5" 275 | } 276 | }, 277 | "nbformat": 4, 278 | "nbformat_minor": 4 279 | } 280 | -------------------------------------------------------------------------------- /05. More on Loops/More On Loops.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/05. More on Loops/More On Loops.pdf -------------------------------------------------------------------------------- /06. Functions/1. Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 10, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "4\n", 13 | "2\n", 14 | "6\n" 15 | ] 16 | } 17 | ], 18 | "source": [ 19 | "n = int(input())\n", 20 | "r = int(input())\n", 21 | "\n", 22 | "n_fact= 1\n", 23 | "for i in range (1,n+1):\n", 24 | " n_fact=n_fact*i\n", 25 | " \n", 26 | "r_fact= 1\n", 27 | "for i in range (1,r+1):\n", 28 | " r_fact=r_fact*i\n", 29 | "\n", 30 | "n_r_fact= 1\n", 31 | "for i in range (1,n-r+1):\n", 32 | " n_r_fact=n_r_fact*i\n", 33 | " \n", 34 | "ans = n_fact//(r_fact*n_r_fact)\n", 35 | "\n", 36 | "print(ans)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 32, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "def fact(a):\n", 46 | " a_fact = 1\n", 47 | " for i in range(1,a+1):\n", 48 | " a_fact=a_fact*i\n", 49 | " return a_fact" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 6, 55 | "metadata": { 56 | "scrolled": true 57 | }, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "24" 63 | ] 64 | }, 65 | "execution_count": 6, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "fact(4)" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 9, 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "5\n", 84 | "2\n", 85 | "10\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "def fact(a):\n", 91 | " a_fact = 1\n", 92 | " for i in range(1,a+1):\n", 93 | " a_fact=a_fact*i\n", 94 | " return a_fact\n", 95 | "\n", 96 | "n = int(input())\n", 97 | "r = int(input())\n", 98 | "\n", 99 | "n_fact= fact(n)\n", 100 | "r_fact= fact(r)\n", 101 | "n_r_fact= fact(n-r)\n", 102 | "\n", 103 | "ans = n_fact//(r_fact*n_r_fact)\n", 104 | "print(ans)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 20, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [ 113 | "def isprime(n):\n", 114 | " for d in range(2,n):\n", 115 | " if (n%d==0):\n", 116 | " break\n", 117 | " \n", 118 | " else:\n", 119 | " return True\n", 120 | " \n", 121 | " return False " 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 21, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "False" 133 | ] 134 | }, 135 | "execution_count": 21, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "isprime(10)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 22, 147 | "metadata": { 148 | "scrolled": true 149 | }, 150 | "outputs": [ 151 | { 152 | "data": { 153 | "text/plain": [ 154 | "True" 155 | ] 156 | }, 157 | "execution_count": 22, 158 | "metadata": {}, 159 | "output_type": "execute_result" 160 | } 161 | ], 162 | "source": [ 163 | "isprime(17)" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 27, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "def primefrom2ton(n):\n", 173 | " for k in range(2,n+1):\n", 174 | " is_k_prime=isprime(k)\n", 175 | " if (is_k_prime):\n", 176 | " print(k)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 29, 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "name": "stdout", 186 | "output_type": "stream", 187 | "text": [ 188 | "2\n", 189 | "3\n", 190 | "5\n", 191 | "7\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "primefrom2ton(10)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 35, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "def ncr(n,r):\n", 206 | " n_fact = fact(n)\n", 207 | " r_fact = fact(r)\n", 208 | " n_r_fact = fact(n-r)\n", 209 | " ans = n_fact//(r_fact*n_r_fact)\n", 210 | " return ans" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 36, 216 | "metadata": {}, 217 | "outputs": [ 218 | { 219 | "data": { 220 | "text/plain": [ 221 | "10" 222 | ] 223 | }, 224 | "execution_count": 36, 225 | "metadata": {}, 226 | "output_type": "execute_result" 227 | } 228 | ], 229 | "source": [ 230 | "ncr(5,2)" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 7, 236 | "metadata": { 237 | "scrolled": false 238 | }, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "11\n" 245 | ] 246 | } 247 | ], 248 | "source": [ 249 | "def function(a,b,c=1,d=5):\n", 250 | " return a+b+c+d\n", 251 | "value = function(1,2,d=7)\n", 252 | "print(value)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 27, 258 | "metadata": { 259 | "scrolled": true 260 | }, 261 | "outputs": [ 262 | { 263 | "name": "stdout", 264 | "output_type": "stream", 265 | "text": [ 266 | "Enter a number: 1\n", 267 | "True\n" 268 | ] 269 | } 270 | ], 271 | "source": [ 272 | "# take input from the user\n", 273 | "num = int(input(\"Enter a number: \"))\n", 274 | "\n", 275 | "# initialize sum\n", 276 | "sum = 0\n", 277 | "\n", 278 | "# find the sum of the cube of each digit\n", 279 | "temp = num\n", 280 | "while temp > 0:\n", 281 | " digit = temp % 10\n", 282 | " sum += digit ** 3\n", 283 | " temp //= 10\n", 284 | "\n", 285 | "# display the result\n", 286 | "if num == sum:\n", 287 | " print(\"True\")\n", 288 | "else:\n", 289 | " print(\"False\")" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 45, 295 | "metadata": {}, 296 | "outputs": [ 297 | { 298 | "name": "stdout", 299 | "output_type": "stream", 300 | "text": [ 301 | "1\n", 302 | "true\n" 303 | ] 304 | } 305 | ], 306 | "source": [ 307 | "num = int(input())\n", 308 | "\n", 309 | "\n", 310 | "sum = 0\n", 311 | "\n", 312 | "\n", 313 | "temp = num\n", 314 | "while temp > 0:\n", 315 | " digit = temp % 10\n", 316 | " sum += digit ** 3\n", 317 | " temp //= 10\n", 318 | "\n", 319 | "\n", 320 | "if num == sum:\n", 321 | " print(\"true\")\n", 322 | "else:\n", 323 | " print(\"false\")" 324 | ] 325 | } 326 | ], 327 | "metadata": { 328 | "kernelspec": { 329 | "display_name": "Python 3", 330 | "language": "python", 331 | "name": "python3" 332 | }, 333 | "language_info": { 334 | "codemirror_mode": { 335 | "name": "ipython", 336 | "version": 3 337 | }, 338 | "file_extension": ".py", 339 | "mimetype": "text/x-python", 340 | "name": "python", 341 | "nbconvert_exporter": "python", 342 | "pygments_lexer": "ipython3", 343 | "version": "3.8.5" 344 | } 345 | }, 346 | "nbformat": 4, 347 | "nbformat_minor": 4 348 | } 349 | -------------------------------------------------------------------------------- /06. Functions/3. Default parameters in functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#like print(\"a\")\n", 10 | "#print(a,end='')" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 1, 16 | "metadata": {}, 17 | "outputs": [ 18 | { 19 | "ename": "TypeError", 20 | "evalue": "sum() takes 2 positional arguments but 3 were given", 21 | "output_type": "error", 22 | "traceback": [ 23 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 24 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 25 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 26 | "\u001b[1;31mTypeError\u001b[0m: sum() takes 2 positional arguments but 3 were given" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "def sum(a,b):\n", 32 | " return a+b\n", 33 | "\n", 34 | "sum(1,2,3)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 4, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "6\n", 47 | "3\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "def sum(a,b,c=0):\n", 53 | " return a+b+c\n", 54 | "\n", 55 | "print(sum(1,2,3))\n", 56 | "print(sum(1,2))" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 5, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "3\n", 69 | "6\n", 70 | "0\n", 71 | "3\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "def sum(a,b,c=0):\n", 77 | " print(c)\n", 78 | " return a+b+c\n", 79 | "\n", 80 | "print(sum(1,2,3))\n", 81 | "print(sum(1,2))" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 6, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "ename": "SyntaxError", 91 | "evalue": "non-default argument follows default argument (, line 1)", 92 | "output_type": "error", 93 | "traceback": [ 94 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m def sum(a=0,b,c):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m non-default argument follows default argument\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "def sum(a=0,b,c):\n", 100 | " return a+b+c\n", 101 | "sum(1,2,3)" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 8, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "7\n", 114 | "10\n", 115 | "14\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "def sum(a,b,c=2,d=0):\n", 121 | " return a+b+c+d\n", 122 | "\n", 123 | "print(sum(2,3))\n", 124 | "print(sum(2,3,5))\n", 125 | "print(sum(2,3,4,5))" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 9, 131 | "metadata": { 132 | "scrolled": true 133 | }, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "10" 139 | ] 140 | }, 141 | "execution_count": 9, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "def sum(a,b,c=2,d=0):\n", 148 | " return a+b+c+d\n", 149 | "\n", 150 | "sum(2,3,d=3)" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "### give numbers or it works in order." 158 | ] 159 | } 160 | ], 161 | "metadata": { 162 | "kernelspec": { 163 | "display_name": "Python 3", 164 | "language": "python", 165 | "name": "python3" 166 | }, 167 | "language_info": { 168 | "codemirror_mode": { 169 | "name": "ipython", 170 | "version": 3 171 | }, 172 | "file_extension": ".py", 173 | "mimetype": "text/x-python", 174 | "name": "python", 175 | "nbconvert_exporter": "python", 176 | "pygments_lexer": "ipython3", 177 | "version": "3.8.5" 178 | } 179 | }, 180 | "nbformat": 4, 181 | "nbformat_minor": 4 182 | } 183 | -------------------------------------------------------------------------------- /06. Functions/Assignment (6).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Fahrenheit to Celsius Function" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "0\n", 20 | "100\n", 21 | "20\n", 22 | "0\t-17\n", 23 | "20\t-6\n", 24 | "40\t4\n", 25 | "60\t15\n", 26 | "80\t26\n", 27 | "100\t37\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "S=int(input())\n", 33 | "E=int(input())\n", 34 | "W=int(input())\n", 35 | "i = S\n", 36 | "while i<=E:\n", 37 | " cel=(5/9)*(i-32)\n", 38 | " \n", 39 | " print(str(i) + \"\\t\" + str(int(cel)))\n", 40 | " i=i+W" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "# Fibonacci Member" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 3, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "14\n", 60 | "false\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "def checkmember(n):\n", 66 | " if (n==0 or n ==1 or n ==2):\n", 67 | " return True\n", 68 | " a = 0\n", 69 | " b = 1\n", 70 | " while (b0:\n", 111 | " R =R*10+ N%10\n", 112 | " N =N//10\n", 113 | "if R ==i:\n", 114 | " print(\"true\")\n", 115 | "else:\n", 116 | " print(\"false\")" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "# Check Armstrong" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 6, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "103\n", 136 | "false\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "def order(m):\n", 142 | " count = 0\n", 143 | " while m != 0:\n", 144 | " m = m // 10\n", 145 | " count = count + 1\n", 146 | " return count\n", 147 | "def num(n):\n", 148 | " sum = 0\n", 149 | " c = order(n)\n", 150 | " while n > 0:\n", 151 | " x = n % 10\n", 152 | " sum = sum + (x**c)\n", 153 | " n = n // 10\n", 154 | " return sum\n", 155 | "y = int(input())\n", 156 | "d = num(y)\n", 157 | "if y == d:\n", 158 | " print('true')\n", 159 | "else:\n", 160 | " print('false')" 161 | ] 162 | } 163 | ], 164 | "metadata": { 165 | "kernelspec": { 166 | "display_name": "Python 3", 167 | "language": "python", 168 | "name": "python3" 169 | }, 170 | "language_info": { 171 | "codemirror_mode": { 172 | "name": "ipython", 173 | "version": 3 174 | }, 175 | "file_extension": ".py", 176 | "mimetype": "text/x-python", 177 | "name": "python", 178 | "nbconvert_exporter": "python", 179 | "pygments_lexer": "ipython3", 180 | "version": "3.8.5" 181 | } 182 | }, 183 | "nbformat": 4, 184 | "nbformat_minor": 4 185 | } 186 | -------------------------------------------------------------------------------- /06. Functions/Functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/06. Functions/Functions.pdf -------------------------------------------------------------------------------- /07. List & Arrays/2. Looping on list.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "li = [1,2,3,\"VAIBHAV\",6,9]" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 2, 15 | "metadata": { 16 | "scrolled": true 17 | }, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "[1, 2, 3, 'VAIBHAV', 6, 9]" 23 | ] 24 | }, 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "li" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 7, 37 | "metadata": { 38 | "scrolled": true 39 | }, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "1\n", 46 | "2\n", 47 | "3\n", 48 | "VAIBHAV\n", 49 | "6\n", 50 | "9\n" 51 | ] 52 | } 53 | ], 54 | "source": [ 55 | "for i in range(len(li)):\n", 56 | " print(li[i])" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 8, 62 | "metadata": { 63 | "scrolled": true 64 | }, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "3\n", 71 | "VAIBHAV\n", 72 | "6\n", 73 | "9\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "for i in range (2,len(li)):\n", 79 | " print(li[i])" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 9, 85 | "metadata": { 86 | "scrolled": true 87 | }, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "1\n", 94 | "2\n", 95 | "3\n", 96 | "VAIBHAV\n", 97 | "6\n", 98 | "9\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "for ele in li:\n", 104 | " print(ele)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 10, 110 | "metadata": { 111 | "scrolled": false 112 | }, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "3\n", 119 | "VAIBHAV\n", 120 | "6\n", 121 | "9\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "for ele in li[2:]:\n", 127 | " print(ele)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 43, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "Enter the size of array:3\n", 140 | "Enter array elements:\n", 141 | "9\n", 142 | "8\n", 143 | "9\n", 144 | "[9, 8, 9]\n", 145 | "26\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "arr =[]\n", 151 | "n = int(input(\"Enter the size of array:\"))\n", 152 | "print('Enter array elements:')\n", 153 | "for i in range(n):\n", 154 | " elements =int(input())\n", 155 | " arr.append(elements) \n", 156 | "print(arr)\n", 157 | "print(sum(arr))" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 23, 163 | "metadata": { 164 | "scrolled": false 165 | }, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "Enter the size of the array: 3\n", 172 | "Enter array elements: \n", 173 | "9\n", 174 | "8\n", 175 | "9\n", 176 | "Sum: 26\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "lst = []\n", 182 | "num = int(input(\"Enter the size of the array: \"))\n", 183 | "print(\"Enter array elements: \")\n", 184 | "for n in range(num):\n", 185 | " numbers = int(input())\n", 186 | " lst.append(numbers)\n", 187 | "print(\"Sum:\", sum(lst))" 188 | ] 189 | } 190 | ], 191 | "metadata": { 192 | "kernelspec": { 193 | "display_name": "Python 3", 194 | "language": "python", 195 | "name": "python3" 196 | }, 197 | "language_info": { 198 | "codemirror_mode": { 199 | "name": "ipython", 200 | "version": 3 201 | }, 202 | "file_extension": ".py", 203 | "mimetype": "text/x-python", 204 | "name": "python", 205 | "nbconvert_exporter": "python", 206 | "pygments_lexer": "ipython3", 207 | "version": "3.8.5" 208 | } 209 | }, 210 | "nbformat": 4, 211 | "nbformat_minor": 4 212 | } 213 | -------------------------------------------------------------------------------- /07. List & Arrays/5. Linear Search.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "6\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "n = int(input())" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 2, 23 | "metadata": { 24 | "scrolled": true 25 | }, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "2 4 7 9 10 13\n" 32 | ] 33 | }, 34 | { 35 | "data": { 36 | "text/plain": [ 37 | "[2, 4, 7, 9, 10, 13]" 38 | ] 39 | }, 40 | "execution_count": 2, 41 | "metadata": {}, 42 | "output_type": "execute_result" 43 | } 44 | ], 45 | "source": [ 46 | "li =[int(x) for x in input().split()]\n", 47 | "li" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 12, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "7\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "ele = int(input())" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 14, 70 | "metadata": { 71 | "scrolled": true 72 | }, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "2\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "isfound = False\n", 84 | "for i in range(len(li)):\n", 85 | " if li[i] == ele:\n", 86 | " print(i)\n", 87 | " isfound =True\n", 88 | " break\n", 89 | "if isfound is False:\n", 90 | " print(-1)" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 15, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "14\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "ele = int(input())" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 16, 113 | "metadata": { 114 | "scrolled": false 115 | }, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "-1\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "isfound =False\n", 127 | "for i in range(len(li)):\n", 128 | " if li[i]==ele:\n", 129 | " print(i)\n", 130 | " isfound =True\n", 131 | " break\n", 132 | "if isfound is False:\n", 133 | " print(-1)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [] 142 | } 143 | ], 144 | "metadata": { 145 | "kernelspec": { 146 | "display_name": "Python 3", 147 | "language": "python", 148 | "name": "python3" 149 | }, 150 | "language_info": { 151 | "codemirror_mode": { 152 | "name": "ipython", 153 | "version": 3 154 | }, 155 | "file_extension": ".py", 156 | "mimetype": "text/x-python", 157 | "name": "python", 158 | "nbconvert_exporter": "python", 159 | "pygments_lexer": "ipython3", 160 | "version": "3.8.5" 161 | } 162 | }, 163 | "nbformat": 4, 164 | "nbformat_minor": 4 165 | } 166 | -------------------------------------------------------------------------------- /07. List & Arrays/6. Linear Search Through Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 7, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "def linear_search(li,ele):\n", 10 | " for i in range(len(li)):\n", 11 | " if li[i] ==ele:\n", 12 | " return i\n", 13 | " return -1" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 9, 19 | "metadata": { 20 | "scrolled": true 21 | }, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "3\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "li = [1,2,6,9,5]\n", 33 | "index = linear_search(li,9)\n", 34 | "print(index)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 10, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "-1\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "li = [1,2,6,9,5]\n", 52 | "index = linear_search(li,10)\n", 53 | "print(index)" 54 | ] 55 | } 56 | ], 57 | "metadata": { 58 | "kernelspec": { 59 | "display_name": "Python 3", 60 | "language": "python", 61 | "name": "python3" 62 | }, 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.8.5" 74 | } 75 | }, 76 | "nbformat": 4, 77 | "nbformat_minor": 4 78 | } 79 | -------------------------------------------------------------------------------- /07. List & Arrays/7. Mutable And Immutable Concept.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### IMMUTABLE" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "3\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "x =3\n", 27 | "a =3\n", 28 | "print(x)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": { 35 | "scrolled": true 36 | }, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "140706021648224" 42 | ] 43 | }, 44 | "execution_count": 2, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "id(x)" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 3, 56 | "metadata": { 57 | "scrolled": true 58 | }, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "140706021648224" 64 | ] 65 | }, 66 | "execution_count": 3, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "id (a)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 4, 78 | "metadata": { 79 | "scrolled": true 80 | }, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "140706021648256" 86 | ] 87 | }, 88 | "execution_count": 4, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "a =4\n", 95 | "id(a)" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 5, 101 | "metadata": { 102 | "scrolled": true 103 | }, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "3" 109 | ] 110 | }, 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "x" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "### MUTABLE" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 8, 130 | "metadata": { 131 | "scrolled": true 132 | }, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "[1, 2, 7, 4, 5]" 138 | ] 139 | }, 140 | "execution_count": 8, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "li = [1,2,3,4,5]\n", 147 | "li2 = li\n", 148 | "li2[2] = 7\n", 149 | "li2" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 9, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "[6, 7, 7]" 161 | ] 162 | }, 163 | "execution_count": 9, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "li = [1,2,3,4,5]\n", 170 | "li2 = li\n", 171 | "li2 = [6,7,8]\n", 172 | "li2[2] = 7\n", 173 | "li2" 174 | ] 175 | } 176 | ], 177 | "metadata": { 178 | "kernelspec": { 179 | "display_name": "Python 3", 180 | "language": "python", 181 | "name": "python3" 182 | }, 183 | "language_info": { 184 | "codemirror_mode": { 185 | "name": "ipython", 186 | "version": 3 187 | }, 188 | "file_extension": ".py", 189 | "mimetype": "text/x-python", 190 | "name": "python", 191 | "nbconvert_exporter": "python", 192 | "pygments_lexer": "ipython3", 193 | "version": "3.8.5" 194 | } 195 | }, 196 | "nbformat": 4, 197 | "nbformat_minor": 4 198 | } 199 | -------------------------------------------------------------------------------- /07. List & Arrays/8. Passing V & L Through Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Passing V Through Functions" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "2\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "def increment(a):\n", 27 | " a = a+2\n", 28 | " return\n", 29 | "\n", 30 | "a =2\n", 31 | "increment(a)\n", 32 | "print(a)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 4, 38 | "metadata": { 39 | "scrolled": true 40 | }, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "4\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "def increment(a):\n", 52 | " a = a+2\n", 53 | " return a\n", 54 | "\n", 55 | "a =2\n", 56 | "a = increment(a)\n", 57 | "print(a)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "### Passing L Through Functions" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "[3, 2, 3, 4]\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "def increment(li):\n", 82 | " li[0]= li[0]+2\n", 83 | " return\n", 84 | "\n", 85 | "li =[1,2,3,4]\n", 86 | "increment(li)\n", 87 | "print(li)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 8, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "[1, 2, 3, 4]\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "def increment(li):\n", 105 | " li = [3,3,4]\n", 106 | " return\n", 107 | "\n", 108 | "li =[1,2,3,4]\n", 109 | "increment(li)\n", 110 | "print(li)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 10, 116 | "metadata": { 117 | "scrolled": true 118 | }, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "[3, 3, 4]\n" 125 | ] 126 | } 127 | ], 128 | "source": [ 129 | "def increment(li):\n", 130 | " li = [3,3,4]\n", 131 | " return li\n", 132 | "\n", 133 | "li =[1,2,3,4]\n", 134 | "li = increment(li)\n", 135 | "print(li)" 136 | ] 137 | } 138 | ], 139 | "metadata": { 140 | "kernelspec": { 141 | "display_name": "Python 3", 142 | "language": "python", 143 | "name": "python3" 144 | }, 145 | "language_info": { 146 | "codemirror_mode": { 147 | "name": "ipython", 148 | "version": 3 149 | }, 150 | "file_extension": ".py", 151 | "mimetype": "text/x-python", 152 | "name": "python", 153 | "nbconvert_exporter": "python", 154 | "pygments_lexer": "ipython3", 155 | "version": "3.8.5" 156 | } 157 | }, 158 | "nbformat": 4, 159 | "nbformat_minor": 4 160 | } 161 | -------------------------------------------------------------------------------- /07. List & Arrays/9. Reverse List.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "[6, 5, 4, 3, 2, 1]\n" 15 | ] 16 | } 17 | ], 18 | "source": [ 19 | "def reverse_l(li):\n", 20 | " length = len(li)\n", 21 | " for i in range(length//2):\n", 22 | " li[i],li[length-i-1]=li[length-i-1],li[i]\n", 23 | "\n", 24 | "li = [1,2,3,4,5,6]\n", 25 | "reverse_l(li)\n", 26 | "print(li)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "metadata": { 33 | "scrolled": true 34 | }, 35 | "outputs": [ 36 | { 37 | "name": "stdout", 38 | "output_type": "stream", 39 | "text": [ 40 | "[6, 5, 4, 3, 2, 1]\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "def reverse_l(li):\n", 46 | " length = len(li)\n", 47 | " for i in range(length//2):\n", 48 | " li[i],li[-i-1]=li[-i-1],li[i]\n", 49 | "\n", 50 | "li = [1,2,3,4,5,6]\n", 51 | "reverse_l(li)\n", 52 | "print(li)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": { 59 | "scrolled": true 60 | }, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "[6, 5, 4, 3, 2, 1]" 66 | ] 67 | }, 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "output_type": "execute_result" 71 | } 72 | ], 73 | "source": [ 74 | "li" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 16, 80 | "metadata": { 81 | "scrolled": false 82 | }, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "[6, 5, 4, 3, 2, 1]" 88 | ] 89 | }, 90 | "execution_count": 16, 91 | "metadata": {}, 92 | "output_type": "execute_result" 93 | } 94 | ], 95 | "source": [ 96 | "li = [1, 2, 3, 4, 5, 6]\n", 97 | "li = li[::-1]\n", 98 | "li" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [] 107 | } 108 | ], 109 | "metadata": { 110 | "kernelspec": { 111 | "display_name": "Python 3", 112 | "language": "python", 113 | "name": "python3" 114 | }, 115 | "language_info": { 116 | "codemirror_mode": { 117 | "name": "ipython", 118 | "version": 3 119 | }, 120 | "file_extension": ".py", 121 | "mimetype": "text/x-python", 122 | "name": "python", 123 | "nbconvert_exporter": "python", 124 | "pygments_lexer": "ipython3", 125 | "version": "3.8.5" 126 | } 127 | }, 128 | "nbformat": 4, 129 | "nbformat_minor": 4 130 | } 131 | -------------------------------------------------------------------------------- /07. List & Arrays/Lists and Arrays .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/07. List & Arrays/Lists and Arrays .pdf -------------------------------------------------------------------------------- /08. Searching and Sorting/1. Binary Search.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "8\n" 15 | ] 16 | } 17 | ], 18 | "source": [ 19 | "def binarySearch(arr,element):\n", 20 | " start = 0\n", 21 | " end = len(arr)-1\n", 22 | " while (start<=end):\n", 23 | " mid = (start+end)//2\n", 24 | " if (arr[mid]==element):\n", 25 | " return mid\n", 26 | " elif(arr[mid] arr[j+1]):\n", 22 | " arr[j],arr[j+1]=arr[j+1],arr[j]\n", 23 | " \n", 24 | "arr = [6,4,5,1,7,3]\n", 25 | "bubbleSort(arr)\n", 26 | "print(arr)" 27 | ] 28 | } 29 | ], 30 | "metadata": { 31 | "kernelspec": { 32 | "display_name": "Python 3", 33 | "language": "python", 34 | "name": "python3" 35 | }, 36 | "language_info": { 37 | "codemirror_mode": { 38 | "name": "ipython", 39 | "version": 3 40 | }, 41 | "file_extension": ".py", 42 | "mimetype": "text/x-python", 43 | "name": "python", 44 | "nbconvert_exporter": "python", 45 | "pygments_lexer": "ipython3", 46 | "version": "3.8.5" 47 | } 48 | }, 49 | "nbformat": 4, 50 | "nbformat_minor": 4 51 | } 52 | -------------------------------------------------------------------------------- /08. Searching and Sorting/4. Insertion Sort.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 3, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "[1, 5, 6, 7, 8, 9]\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "def insertSort(arr):\n", 18 | " length = len(arr)\n", 19 | " for i in range(1,length):\n", 20 | " j = i-1\n", 21 | " temp = arr[i]\n", 22 | " while (j>=0 and arr[j]>temp):\n", 23 | " arr[j+1]=arr[j]\n", 24 | " j = j-1\n", 25 | " arr[j+1]=temp\n", 26 | "\n", 27 | "arr = [9,8,5,6,7,1]\n", 28 | "insertSort(arr)\n", 29 | "print(arr)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": null, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [] 38 | } 39 | ], 40 | "metadata": { 41 | "kernelspec": { 42 | "display_name": "Python 3", 43 | "language": "python", 44 | "name": "python3" 45 | }, 46 | "language_info": { 47 | "codemirror_mode": { 48 | "name": "ipython", 49 | "version": 3 50 | }, 51 | "file_extension": ".py", 52 | "mimetype": "text/x-python", 53 | "name": "python", 54 | "nbconvert_exporter": "python", 55 | "pygments_lexer": "ipython3", 56 | "version": "3.8.5" 57 | } 58 | }, 59 | "nbformat": 4, 60 | "nbformat_minor": 4 61 | } 62 | -------------------------------------------------------------------------------- /08. Searching and Sorting/5. Merge Two Sorted Arrays.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "[1, 2, 3, 4, 6, 7, 8, 9, 10]\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "def mergeSortedArrays(arr1,arr2):\n", 18 | " i = 0\n", 19 | " j = 0\n", 20 | " len1 =len(arr1)\n", 21 | " len2 =len(arr2)\n", 22 | " \n", 23 | " arr = []\n", 24 | " \n", 25 | " while (i\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"Marron\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mg\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mg\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 278 | "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 279 | ] 280 | } 281 | ], 282 | "source": [ 283 | "g = \"Marron\"\n", 284 | "g = g+3\n", 285 | "g" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 43, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "data": { 295 | "text/plain": [ 296 | "'Marron3'" 297 | ] 298 | }, 299 | "execution_count": 43, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "g =\"Marron\"\n", 306 | "g = g+str(3)\n", 307 | "g" 308 | ] 309 | } 310 | ], 311 | "metadata": { 312 | "kernelspec": { 313 | "display_name": "Python 3", 314 | "language": "python", 315 | "name": "python3" 316 | }, 317 | "language_info": { 318 | "codemirror_mode": { 319 | "name": "ipython", 320 | "version": 3 321 | }, 322 | "file_extension": ".py", 323 | "mimetype": "text/x-python", 324 | "name": "python", 325 | "nbconvert_exporter": "python", 326 | "pygments_lexer": "ipython3", 327 | "version": "3.8.5" 328 | } 329 | }, 330 | "nbformat": 4, 331 | "nbformat_minor": 4 332 | } 333 | -------------------------------------------------------------------------------- /09. Strings/3. Slicing of Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "S = \"parikh\"" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 3, 15 | "metadata": { 16 | "scrolled": true 17 | }, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "'ari'" 23 | ] 24 | }, 25 | "execution_count": 3, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "S[1:4]" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 4, 37 | "metadata": { 38 | "scrolled": true 39 | }, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "'ai'" 45 | ] 46 | }, 47 | "execution_count": 4, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "S[1:4:2]" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 5, 59 | "metadata": { 60 | "scrolled": true 61 | }, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "''" 67 | ] 68 | }, 69 | "execution_count": 5, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "S[6:4]" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 6, 81 | "metadata": { 82 | "scrolled": true 83 | }, 84 | "outputs": [ 85 | { 86 | "data": { 87 | "text/plain": [ 88 | "'h'" 89 | ] 90 | }, 91 | "execution_count": 6, 92 | "metadata": {}, 93 | "output_type": "execute_result" 94 | } 95 | ], 96 | "source": [ 97 | "S[-1]" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 7, 103 | "metadata": { 104 | "scrolled": true 105 | }, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "'ar'" 111 | ] 112 | }, 113 | "execution_count": 7, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "S[-5:-3]" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 8, 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "data": { 129 | "text/plain": [ 130 | "'arikh'" 131 | ] 132 | }, 133 | "execution_count": 8, 134 | "metadata": {}, 135 | "output_type": "execute_result" 136 | } 137 | ], 138 | "source": [ 139 | "S[1:]" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 9, 145 | "metadata": { 146 | "scrolled": true 147 | }, 148 | "outputs": [ 149 | { 150 | "data": { 151 | "text/plain": [ 152 | "'pari'" 153 | ] 154 | }, 155 | "execution_count": 9, 156 | "metadata": {}, 157 | "output_type": "execute_result" 158 | } 159 | ], 160 | "source": [ 161 | "S[:4]" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 10, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "data": { 171 | "text/plain": [ 172 | "'arikh'" 173 | ] 174 | }, 175 | "execution_count": 10, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "S[1:9]" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 11, 187 | "metadata": { 188 | "scrolled": true 189 | }, 190 | "outputs": [ 191 | { 192 | "data": { 193 | "text/plain": [ 194 | "'kir'" 195 | ] 196 | }, 197 | "execution_count": 11, 198 | "metadata": {}, 199 | "output_type": "execute_result" 200 | } 201 | ], 202 | "source": [ 203 | "S[4:1:-1]" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 12, 209 | "metadata": { 210 | "scrolled": true 211 | }, 212 | "outputs": [ 213 | { 214 | "data": { 215 | "text/plain": [ 216 | "'hkirap'" 217 | ] 218 | }, 219 | "execution_count": 12, 220 | "metadata": {}, 221 | "output_type": "execute_result" 222 | } 223 | ], 224 | "source": [ 225 | "S[5::-1]" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 13, 231 | "metadata": { 232 | "scrolled": true 233 | }, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "'hki'" 239 | ] 240 | }, 241 | "execution_count": 13, 242 | "metadata": {}, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "S[:2:-1]" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 14, 253 | "metadata": { 254 | "scrolled": true 255 | }, 256 | "outputs": [ 257 | { 258 | "data": { 259 | "text/plain": [ 260 | "'hi'" 261 | ] 262 | }, 263 | "execution_count": 14, 264 | "metadata": {}, 265 | "output_type": "execute_result" 266 | } 267 | ], 268 | "source": [ 269 | "S[5:1:-2]" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 15, 275 | "metadata": {}, 276 | "outputs": [ 277 | { 278 | "data": { 279 | "text/plain": [ 280 | "'hkirap'" 281 | ] 282 | }, 283 | "execution_count": 15, 284 | "metadata": {}, 285 | "output_type": "execute_result" 286 | } 287 | ], 288 | "source": [ 289 | "S[::-1]" 290 | ] 291 | } 292 | ], 293 | "metadata": { 294 | "kernelspec": { 295 | "display_name": "Python 3", 296 | "language": "python", 297 | "name": "python3" 298 | }, 299 | "language_info": { 300 | "codemirror_mode": { 301 | "name": "ipython", 302 | "version": 3 303 | }, 304 | "file_extension": ".py", 305 | "mimetype": "text/x-python", 306 | "name": "python", 307 | "nbconvert_exporter": "python", 308 | "pygments_lexer": "ipython3", 309 | "version": "3.8.5" 310 | } 311 | }, 312 | "nbformat": 4, 313 | "nbformat_minor": 4 314 | } 315 | -------------------------------------------------------------------------------- /09. Strings/4. Iterating on Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "str = \"Hello World\"" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 4, 15 | "metadata": { 16 | "scrolled": true 17 | }, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "3\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "count = 0\n", 29 | "for letter in str:\n", 30 | " if (letter == \"l\"):\n", 31 | " count = count +1\n", 32 | "print(count)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "2nd Way" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 7, 45 | "metadata": { 46 | "scrolled": true 47 | }, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "3\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "count = 0\n", 59 | "for i in range(len(str)):\n", 60 | " if (str[i]== \"l\"):\n", 61 | " count = count+1\n", 62 | " \n", 63 | "print(count)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "in and not in Operation on strings" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 8, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [ 79 | "str = \"hello\"" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 10, 85 | "metadata": { 86 | "scrolled": true 87 | }, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "Y\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "if \"hel\" in str:\n", 99 | " print(\"Y\")" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 12, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "N\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "if \"le\" in str:\n", 117 | " print(\"Y\")\n", 118 | "else:\n", 119 | " print('N')" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.8.5" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 4 144 | } 145 | -------------------------------------------------------------------------------- /09. Strings/5. Comparison Operator on Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "==\n", 8 | "!=\n", 9 | ">\n", 10 | "<\n", 11 | ">=\n", 12 | "<=" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": { 19 | "scrolled": true 20 | }, 21 | "outputs": [ 22 | { 23 | "data": { 24 | "text/plain": [ 25 | "True" 26 | ] 27 | }, 28 | "execution_count": 1, 29 | "metadata": {}, 30 | "output_type": "execute_result" 31 | } 32 | ], 33 | "source": [ 34 | "a = \"parikh\" =='parikh'\n", 35 | "a" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "metadata": { 42 | "scrolled": true 43 | }, 44 | "outputs": [ 45 | { 46 | "data": { 47 | "text/plain": [ 48 | "True" 49 | ] 50 | }, 51 | "execution_count": 2, 52 | "metadata": {}, 53 | "output_type": "execute_result" 54 | } 55 | ], 56 | "source": [ 57 | "a = 'rarikh' >='parikh'\n", 58 | "a" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 3, 64 | "metadata": { 65 | "scrolled": true 66 | }, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/plain": [ 71 | "True" 72 | ] 73 | }, 74 | "execution_count": 3, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "a = 'parikh'>= 'Parikh'\n", 81 | "a" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 4, 87 | "metadata": { 88 | "scrolled": false 89 | }, 90 | "outputs": [ 91 | { 92 | "data": { 93 | "text/plain": [ 94 | "False" 95 | ] 96 | }, 97 | "execution_count": 4, 98 | "metadata": {}, 99 | "output_type": "execute_result" 100 | } 101 | ], 102 | "source": [ 103 | "a = 'par' >= 'parikh'\n", 104 | "a" 105 | ] 106 | } 107 | ], 108 | "metadata": { 109 | "kernelspec": { 110 | "display_name": "Python 3", 111 | "language": "python", 112 | "name": "python3" 113 | }, 114 | "language_info": { 115 | "codemirror_mode": { 116 | "name": "ipython", 117 | "version": 3 118 | }, 119 | "file_extension": ".py", 120 | "mimetype": "text/x-python", 121 | "name": "python", 122 | "nbconvert_exporter": "python", 123 | "pygments_lexer": "ipython3", 124 | "version": "3.8.5" 125 | } 126 | }, 127 | "nbformat": 4, 128 | "nbformat_minor": 4 129 | } 130 | -------------------------------------------------------------------------------- /09. Strings/6. Operation on Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### Split" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 3, 13 | "metadata": { 14 | "scrolled": false 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "['My', 'Name', 'Is', 'Parikh']\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "str = \"My Name Is Parikh\"\n", 27 | "li = str.split()\n", 28 | "print(li)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 10, 34 | "metadata": { 35 | "scrolled": true 36 | }, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "['My', 'Name Is Parikh']\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "str = \"My Name Is Parikh\"\n", 48 | "li = str.split(' ',1)\n", 49 | "print(li)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "# Replace" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 12, 62 | "metadata": { 63 | "scrolled": false 64 | }, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "my name is rohan\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "str = \"my name is parikh\"\n", 76 | "str = str.replace(\"parikh\",\"rohan\")\n", 77 | "print(str)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 13, 83 | "metadata": { 84 | "scrolled": true 85 | }, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "my name is rohan rohan rohan\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "str = \"my name is parikh parikh parikh\"\n", 97 | "str = str.replace(\"parikh\",\"rohan\")\n", 98 | "print(str)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 14, 104 | "metadata": { 105 | "scrolled": true 106 | }, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "my name is rohan rohan parikh\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "str = \"my name is parikh parikh parikh\"\n", 118 | "str = str.replace(\"parikh\",\"rohan\",2)\n", 119 | "print(str)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "### FIND" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 16, 132 | "metadata": { 133 | "scrolled": false 134 | }, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "3\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "str = 'My Name is Parikh'\n", 146 | "index = str.find(\"Na\")\n", 147 | "print(index)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 21, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "name": "stdout", 157 | "output_type": "stream", 158 | "text": [ 159 | "-1\n" 160 | ] 161 | } 162 | ], 163 | "source": [ 164 | "str = 'My Name is Parikh'\n", 165 | "index = str.find(\"ra\")\n", 166 | "print(index)" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 17, 172 | "metadata": { 173 | "scrolled": true 174 | }, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "11\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "str = \"my name is parikh parikh\"\n", 186 | "index = str.find(\"par\")\n", 187 | "print(index)" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 19, 193 | "metadata": { 194 | "scrolled": true 195 | }, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "18\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "str = \"my name is parikh parikh\"\n", 207 | "index = str.find(\"par\",16,21)\n", 208 | "print(index)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "### Lower and Upper" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 22, 221 | "metadata": { 222 | "scrolled": true 223 | }, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "my name is parikh\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "str = 'My name is Parikh'\n", 235 | "str = str.lower()\n", 236 | "print(str)" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 23, 242 | "metadata": { 243 | "scrolled": true 244 | }, 245 | "outputs": [ 246 | { 247 | "name": "stdout", 248 | "output_type": "stream", 249 | "text": [ 250 | "MY NAME IS PARIKH\n" 251 | ] 252 | } 253 | ], 254 | "source": [ 255 | "str = 'my name is parikh'\n", 256 | "str = str.upper()\n", 257 | "print(str)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "metadata": {}, 263 | "source": [ 264 | "## Startswith" 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": 25, 270 | "metadata": { 271 | "scrolled": true 272 | }, 273 | "outputs": [ 274 | { 275 | "name": "stdout", 276 | "output_type": "stream", 277 | "text": [ 278 | "True\n" 279 | ] 280 | } 281 | ], 282 | "source": [ 283 | "str = 'my name is parikh'\n", 284 | "ans = str.startswith(\"my na\")\n", 285 | "print(ans)" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 28, 291 | "metadata": { 292 | "scrolled": true 293 | }, 294 | "outputs": [ 295 | { 296 | "name": "stdout", 297 | "output_type": "stream", 298 | "text": [ 299 | "False\n" 300 | ] 301 | } 302 | ], 303 | "source": [ 304 | "str = 'my name is parikh'\n", 305 | "ans = str.startswith(\"my nae\")\n", 306 | "print(ans)" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 35, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "name": "stdout", 316 | "output_type": "stream", 317 | "text": [ 318 | "True\n" 319 | ] 320 | } 321 | ], 322 | "source": [ 323 | "str = 'my name is parikh'\n", 324 | "ans = str.startswith(\"pa\",11,18)\n", 325 | "print(ans)" 326 | ] 327 | } 328 | ], 329 | "metadata": { 330 | "kernelspec": { 331 | "display_name": "Python 3", 332 | "language": "python", 333 | "name": "python3" 334 | }, 335 | "language_info": { 336 | "codemirror_mode": { 337 | "name": "ipython", 338 | "version": 3 339 | }, 340 | "file_extension": ".py", 341 | "mimetype": "text/x-python", 342 | "name": "python", 343 | "nbconvert_exporter": "python", 344 | "pygments_lexer": "ipython3", 345 | "version": "3.8.5" 346 | } 347 | }, 348 | "nbformat": 4, 349 | "nbformat_minor": 4 350 | } 351 | -------------------------------------------------------------------------------- /09. Strings/7. Replace Character in Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "ebcde\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "def replace(str,char1,char2):\n", 18 | " \n", 19 | " newStr = \"\"\n", 20 | " for char in str:\n", 21 | " if (char == char1):\n", 22 | " newStr +=char2\n", 23 | " else:\n", 24 | " newStr+= char\n", 25 | " return newStr\n", 26 | " \n", 27 | "str = \"abcda\"\n", 28 | "str = replace(str,\"a\",\"e\")\n", 29 | "print(str)" 30 | ] 31 | } 32 | ], 33 | "metadata": { 34 | "kernelspec": { 35 | "display_name": "Python 3", 36 | "language": "python", 37 | "name": "python3" 38 | }, 39 | "language_info": { 40 | "codemirror_mode": { 41 | "name": "ipython", 42 | "version": 3 43 | }, 44 | "file_extension": ".py", 45 | "mimetype": "text/x-python", 46 | "name": "python", 47 | "nbconvert_exporter": "python", 48 | "pygments_lexer": "ipython3", 49 | "version": "3.8.5" 50 | } 51 | }, 52 | "nbformat": 4, 53 | "nbformat_minor": 4 54 | } 55 | -------------------------------------------------------------------------------- /09. Strings/8. Count on Strings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "3 4 3 2\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "def countInString(str):\n", 18 | " v,c,d,s=0,0,0,0\n", 19 | " \n", 20 | " for char in str:\n", 21 | " if (char>='a'and char<='z')or(char>=\"A\"and char<='Z'):\n", 22 | " char = char.lower()\n", 23 | " if (char==\"a\" or char =='e'or char ==\"i\" or char =='o'or char =='u'):\n", 24 | " v+=1\n", 25 | " else:\n", 26 | " c+=1\n", 27 | " elif (char>=\"0\"and char<=\"9\"):\n", 28 | " d+=1\n", 29 | " else:\n", 30 | " s+=1\n", 31 | " return v,c,d,s\n", 32 | "\n", 33 | "str = \"Vaibhav@123!\"\n", 34 | "v,c,d,s=countInString(str)\n", 35 | "print(v,c,d,s) " 36 | ] 37 | } 38 | ], 39 | "metadata": { 40 | "kernelspec": { 41 | "display_name": "Python 3", 42 | "language": "python", 43 | "name": "python3" 44 | }, 45 | "language_info": { 46 | "codemirror_mode": { 47 | "name": "ipython", 48 | "version": 3 49 | }, 50 | "file_extension": ".py", 51 | "mimetype": "text/x-python", 52 | "name": "python", 53 | "nbconvert_exporter": "python", 54 | "pygments_lexer": "ipython3", 55 | "version": "3.8.5" 56 | } 57 | }, 58 | "nbformat": 4, 59 | "nbformat_minor": 4 60 | } 61 | -------------------------------------------------------------------------------- /09. Strings/Assignment (9).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Check Palindrome" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 3, 13 | "metadata": { 14 | "scrolled": true 15 | }, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "true\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "from sys import stdin\n", 27 | "\n", 28 | "\n", 29 | "def isPalindrome(string) :\n", 30 | " left =0\n", 31 | " right= len(string)-1\n", 32 | " \n", 33 | " while left\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mli\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 81 | "\u001b[1;31mIndexError\u001b[0m: list index out of range" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "li[2][5]" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 5, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "[[1, 2, 3, 4], [5, 6, 20, 8], [9, 10, 11, 12], [13, 14, 15, 16]]" 98 | ] 99 | }, 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "li[1][2]=20\n", 107 | "li" 108 | ] 109 | } 110 | ], 111 | "metadata": { 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.8.5" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 4 132 | } 133 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/2. How Two Dimensional Lists Are Stored.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "[[1, 2, 3, 4], [5, 6, 7, 8]]" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "li = [[1,2,3,4],[5,6,7,8]]\n", 23 | "li" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "[1, 2, 3, 4]" 35 | ] 36 | }, 37 | "execution_count": 2, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "li[0]" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 3, 49 | "metadata": { 50 | "scrolled": true 51 | }, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "list" 57 | ] 58 | }, 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "type(li[0])" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 4, 71 | "metadata": { 72 | "scrolled": true 73 | }, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "2" 79 | ] 80 | }, 81 | "execution_count": 4, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "li[0][1]" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": { 94 | "scrolled": true 95 | }, 96 | "outputs": [ 97 | { 98 | "data": { 99 | "text/plain": [ 100 | "[[1, 4, 3, 4], [5, 6, 7, 8]]" 101 | ] 102 | }, 103 | "execution_count": 5, 104 | "metadata": {}, 105 | "output_type": "execute_result" 106 | } 107 | ], 108 | "source": [ 109 | "li[0][1]=4\n", 110 | "li" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 6, 116 | "metadata": { 117 | "scrolled": true 118 | }, 119 | "outputs": [ 120 | { 121 | "data": { 122 | "text/plain": [ 123 | "1839499451136" 124 | ] 125 | }, 126 | "execution_count": 6, 127 | "metadata": {}, 128 | "output_type": "execute_result" 129 | } 130 | ], 131 | "source": [ 132 | "id(li)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 7, 138 | "metadata": { 139 | "scrolled": true 140 | }, 141 | "outputs": [ 142 | { 143 | "data": { 144 | "text/plain": [ 145 | "1839499450880" 146 | ] 147 | }, 148 | "execution_count": 7, 149 | "metadata": {}, 150 | "output_type": "execute_result" 151 | } 152 | ], 153 | "source": [ 154 | "id(li[0])" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 8, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "data": { 164 | "text/plain": [ 165 | "1839499451072" 166 | ] 167 | }, 168 | "execution_count": 8, 169 | "metadata": {}, 170 | "output_type": "execute_result" 171 | } 172 | ], 173 | "source": [ 174 | "id(li[1])" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 9, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "li[1]=\"PArikh\"" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 10, 189 | "metadata": { 190 | "scrolled": true 191 | }, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "[[1, 4, 3, 4], 'PArikh']" 197 | ] 198 | }, 199 | "execution_count": 10, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "li" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 11, 211 | "metadata": { 212 | "scrolled": true 213 | }, 214 | "outputs": [ 215 | { 216 | "data": { 217 | "text/plain": [ 218 | "[[1, 4, 3, 4], [6, 7, 8, 9]]" 219 | ] 220 | }, 221 | "execution_count": 11, 222 | "metadata": {}, 223 | "output_type": "execute_result" 224 | } 225 | ], 226 | "source": [ 227 | "li[1]=[6,7,8,9]\n", 228 | "li" 229 | ] 230 | } 231 | ], 232 | "metadata": { 233 | "kernelspec": { 234 | "display_name": "Python 3", 235 | "language": "python", 236 | "name": "python3" 237 | }, 238 | "language_info": { 239 | "codemirror_mode": { 240 | "name": "ipython", 241 | "version": 3 242 | }, 243 | "file_extension": ".py", 244 | "mimetype": "text/x-python", 245 | "name": "python", 246 | "nbconvert_exporter": "python", 247 | "pygments_lexer": "ipython3", 248 | "version": "3.8.5" 249 | } 250 | }, 251 | "nbformat": 4, 252 | "nbformat_minor": 4 253 | } 254 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/3. Jagged Lists.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "[[1, 2, 0, 3], [7, 8, 9], [9, 2]]" 12 | ] 13 | }, 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "li =[[1,2,0,3],[7,8,9],[9,2]]\n", 21 | "li" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 2, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/plain": [ 32 | "[1, 2, 0, 3]" 33 | ] 34 | }, 35 | "execution_count": 2, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | } 39 | ], 40 | "source": [ 41 | "li[0]" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 3, 47 | "metadata": { 48 | "scrolled": true 49 | }, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/plain": [ 54 | "[7, 8, 9]" 55 | ] 56 | }, 57 | "execution_count": 3, 58 | "metadata": {}, 59 | "output_type": "execute_result" 60 | } 61 | ], 62 | "source": [ 63 | "li[1]" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 4, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "[9, 2]" 75 | ] 76 | }, 77 | "execution_count": 4, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "li[2]" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.8.5" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 4 108 | } 109 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/4. List Comprehension.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 9, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "[1, 2, 3, 4]" 14 | ] 15 | }, 16 | "execution_count": 9, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "li = [1,2,3,4]\n", 23 | "li" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 4, 29 | "metadata": { 30 | "scrolled": true 31 | }, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "[1, 4, 9, 16]\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "li_new =[]\n", 43 | "for ele in li:\n", 44 | " li_new.append(ele**2)\n", 45 | " \n", 46 | "print(li_new)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 5, 52 | "metadata": { 53 | "scrolled": true 54 | }, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/plain": [ 59 | "[1, 4, 9, 16]" 60 | ] 61 | }, 62 | "execution_count": 5, 63 | "metadata": {}, 64 | "output_type": "execute_result" 65 | } 66 | ], 67 | "source": [ 68 | "li_n =[ele**2 for ele in li]\n", 69 | "li_n" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 6, 75 | "metadata": { 76 | "scrolled": true 77 | }, 78 | "outputs": [ 79 | { 80 | "data": { 81 | "text/plain": [ 82 | "[4, 16]" 83 | ] 84 | }, 85 | "execution_count": 6, 86 | "metadata": {}, 87 | "output_type": "execute_result" 88 | } 89 | ], 90 | "source": [ 91 | "li_e_sq =[ele**2 for ele in li if ele%2==0]\n", 92 | "li_e_sq" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 1, 98 | "metadata": { 99 | "scrolled": true 100 | }, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "[6]\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "li = [1,2,3,4,5,6]\n", 112 | "li_23 =[ele for ele in li if ele%2 ==0 if ele%3==0]\n", 113 | "print(li_23)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 3, 119 | "metadata": { 120 | "scrolled": true 121 | }, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "[2, 4]\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "li_1 = [1,2,3,4,5]\n", 133 | "li_2 = [2,4,6,7]\n", 134 | "\n", 135 | "li_inter =[]\n", 136 | "for ele in li_1:\n", 137 | " for ele_2 in li_2:\n", 138 | " if ele==ele_2:\n", 139 | " li_inter.append(ele)\n", 140 | "print(li_inter)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 4, 146 | "metadata": { 147 | "scrolled": true 148 | }, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "[2, 4, 7]\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "li_1 = [1,2,3,4,5,7]\n", 160 | "li_2 = [2,4,6,7]\n", 161 | "li_inter =[ele for ele in li_1 for ele_2 in li_2 if ele ==ele_2]\n", 162 | "print(li_inter)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 6, 168 | "metadata": { 169 | "scrolled": true 170 | }, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "[1, 4, 3, 16, 5]" 176 | ] 177 | }, 178 | "execution_count": 6, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "li =[1,2,3,4,5]\n", 185 | "li_e= [ele**2 if ele %2 ==0 else ele for ele in li]\n", 186 | "li_e" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 7, 192 | "metadata": { 193 | "scrolled": true 194 | }, 195 | "outputs": [ 196 | { 197 | "data": { 198 | "text/plain": [ 199 | "['P', 'a', 'r', 'i', 'k', 'h']" 200 | ] 201 | }, 202 | "execution_count": 7, 203 | "metadata": {}, 204 | "output_type": "execute_result" 205 | } 206 | ], 207 | "source": [ 208 | "s = 'Parikh'\n", 209 | "li = [ele for ele in s]\n", 210 | "li" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": 10, 216 | "metadata": { 217 | "scrolled": true 218 | }, 219 | "outputs": [ 220 | { 221 | "data": { 222 | "text/plain": [ 223 | "[['P', 'a', 'r', 'i', 'k', 'h'],\n", 224 | " ['R', 'o', 'h', 'a', 'n'],\n", 225 | " ['A', 'n', 'k', 'u', 's', 'h']]" 226 | ] 227 | }, 228 | "execution_count": 10, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "li = ['Parikh','Rohan','Ankush']\n", 235 | "li_2a = [[w for w in ele] for ele in li]\n", 236 | "li_2a" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 18, 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "data": { 246 | "text/plain": [ 247 | "[['P', 'a', 'r', 'i', 'k', 'h'],\n", 248 | " ['R', 'o', 'h', 'a', 'n'],\n", 249 | " ['A', 'n', 'k', 'u', 's', 'h']]" 250 | ] 251 | }, 252 | "execution_count": 18, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "li = ['Parikh','Rohan','Ankush']\n", 259 | "li_2a = [[ele for ele in ele] for ele in li]\n", 260 | "li_2a" 261 | ] 262 | } 263 | ], 264 | "metadata": { 265 | "kernelspec": { 266 | "display_name": "Python 3", 267 | "language": "python", 268 | "name": "python3" 269 | }, 270 | "language_info": { 271 | "codemirror_mode": { 272 | "name": "ipython", 273 | "version": 3 274 | }, 275 | "file_extension": ".py", 276 | "mimetype": "text/x-python", 277 | "name": "python", 278 | "nbconvert_exporter": "python", 279 | "pygments_lexer": "ipython3", 280 | "version": "3.8.5" 281 | } 282 | }, 283 | "nbformat": 4, 284 | "nbformat_minor": 4 285 | } 286 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/5. Input of 2D list .ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 8, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "3 4\n", 15 | "1 2 3 4\n", 16 | "1 2 3 4\n", 17 | "1 2 3 4\n" 18 | ] 19 | }, 20 | { 21 | "data": { 22 | "text/plain": [ 23 | "[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]" 24 | ] 25 | }, 26 | "execution_count": 8, 27 | "metadata": {}, 28 | "output_type": "execute_result" 29 | } 30 | ], 31 | "source": [ 32 | "str = input().split()\n", 33 | "n,m = int(str[0]),int(str[1])\n", 34 | "li = [[int(j) for j in input().split()] for i in range(n)]\n", 35 | "li" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 6, 41 | "metadata": { 42 | "scrolled": true 43 | }, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "3\n", 50 | "1 2 3 4\n", 51 | "1 2 3\n", 52 | "1 2\n" 53 | ] 54 | }, 55 | { 56 | "data": { 57 | "text/plain": [ 58 | "[[1, 2, 3, 4], [1, 2, 3], [1, 2]]" 59 | ] 60 | }, 61 | "execution_count": 6, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "#str = input().split()\n", 68 | "n= int (input())\n", 69 | "li = [[int(j) for j in input().split()] for i in range(n)]\n", 70 | "li" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "# 2" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 14, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "3 4\n", 90 | "1 2 3 4 5 6 7 8 9 10 11 12\n" 91 | ] 92 | }, 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]" 97 | ] 98 | }, 99 | "execution_count": 14, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "str = input().split()\n", 106 | "n,m = int(str[0]),int(str[1])\n", 107 | "b = input().split()\n", 108 | "arr = [[int(b[m*i+j])for j in range(m)]for i in range (n)]\n", 109 | "arr" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 12, 115 | "metadata": {}, 116 | "outputs": [ 117 | { 118 | "name": "stdout", 119 | "output_type": "stream", 120 | "text": [ 121 | "3 4 1 2 3 4 5 6 7 8 9 10 11 12\n" 122 | ] 123 | }, 124 | { 125 | "data": { 126 | "text/plain": [ 127 | "[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]" 128 | ] 129 | }, 130 | "execution_count": 12, 131 | "metadata": {}, 132 | "output_type": "execute_result" 133 | } 134 | ], 135 | "source": [ 136 | "str = input().split()\n", 137 | "n,m = int(str[0]),int(str[1])\n", 138 | "b = str[2:]\n", 139 | "arr = [[int(b[m*i+j])for j in range(m)]for i in range (n)]\n", 140 | "arr" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 15, 146 | "metadata": { 147 | "scrolled": true 148 | }, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "3" 154 | ] 155 | }, 156 | "execution_count": 15, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "n" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 16, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "4" 174 | ] 175 | }, 176 | "execution_count": 16, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "m" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": null, 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | } 192 | ], 193 | "metadata": { 194 | "kernelspec": { 195 | "display_name": "Python 3", 196 | "language": "python", 197 | "name": "python3" 198 | }, 199 | "language_info": { 200 | "codemirror_mode": { 201 | "name": "ipython", 202 | "version": 3 203 | }, 204 | "file_extension": ".py", 205 | "mimetype": "text/x-python", 206 | "name": "python", 207 | "nbconvert_exporter": "python", 208 | "pygments_lexer": "ipython3", 209 | "version": "3.8.5" 210 | } 211 | }, 212 | "nbformat": 4, 213 | "nbformat_minor": 4 214 | } 215 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/6. Printing 2D lists Iterating on 2D lists.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "1 2 3 4 \n", 15 | "5 6 7 8 \n", 16 | "9 10 11 12 \n" 17 | ] 18 | } 19 | ], 20 | "source": [ 21 | "li = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]\n", 22 | "n = 3\n", 23 | "m = 4\n", 24 | "\n", 25 | "for i in range(n):\n", 26 | " for j in range(m):\n", 27 | " print(li[i][j],end=' ')\n", 28 | " print()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 2, 34 | "metadata": { 35 | "scrolled": true 36 | }, 37 | "outputs": [ 38 | { 39 | "name": "stdout", 40 | "output_type": "stream", 41 | "text": [ 42 | "1 2 3 4 \n", 43 | "5 6 \n", 44 | "9 10 11 12 \n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "li = [[1,2,3,4],[5,6],[9,10,11,12]]\n", 50 | "n = 3\n", 51 | "for row in li:\n", 52 | " for ele in row:\n", 53 | " print(ele,end=' ')\n", 54 | " print()" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": { 61 | "scrolled": true 62 | }, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "'aabbabcabd'" 68 | ] 69 | }, 70 | "execution_count": 3, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "'ab'.join('abcd')" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 8, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "data": { 86 | "text/plain": [ 87 | "'1ab2ab3'" 88 | ] 89 | }, 90 | "execution_count": 8, 91 | "metadata": {}, 92 | "output_type": "execute_result" 93 | } 94 | ], 95 | "source": [ 96 | "'ab'.join(['1','2','3'])" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 9, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "name": "stdout", 106 | "output_type": "stream", 107 | "text": [ 108 | "1 2 3 4\n", 109 | "5 6\n", 110 | "9 10 11\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "li = [[1,2,3,4],[5,6],[9,10,11]]\n", 116 | "n = 3\n", 117 | "for row in li:\n", 118 | " output = ' '.join([str(ele) for ele in row])\n", 119 | " print(output)" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.8.5" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 4 144 | } 145 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/7. Largest Column Sum In 2D List.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "21 3\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "def lar_Col_Sum(li):\n", 18 | " n = len(li)\n", 19 | " m = len(li[0])\n", 20 | " \n", 21 | " max_sum = -1\n", 22 | " max_col_index = -1\n", 23 | " for j in range (m):\n", 24 | " sum = 0\n", 25 | " for i in range(n):\n", 26 | " sum += li[i][j]\n", 27 | " if sum>max_sum:\n", 28 | " max_col_index= j\n", 29 | " max_sum = sum\n", 30 | " return max_sum,max_col_index\n", 31 | "\n", 32 | "li = [[1,2,3,4],[8,7,6,5],[9,10,11,12]]\n", 33 | "lar_sum,lar_col_Index = lar_Col_Sum(li)\n", 34 | "print(lar_sum,lar_col_Index)" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 4, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "21 3\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "def lar_Col_Sum(li):\n", 52 | " n = len(li)\n", 53 | " m = len(li[0])\n", 54 | " \n", 55 | " max_sum = -1\n", 56 | " max_col_index = -1\n", 57 | " for j in range (m):\n", 58 | " sum = 0\n", 59 | " for ele in li:\n", 60 | " sum += ele[j]\n", 61 | " if sum>max_sum:\n", 62 | " max_col_index= j\n", 63 | " max_sum = sum\n", 64 | " return max_sum,max_col_index\n", 65 | "\n", 66 | "li = [[1,2,3,4],[8,7,6,5],[9,10,11,12]]\n", 67 | "lar_sum,lar_col_Index = lar_Col_Sum(li)\n", 68 | "print(lar_sum,lar_col_Index)" 69 | ] 70 | } 71 | ], 72 | "metadata": { 73 | "kernelspec": { 74 | "display_name": "Python 3", 75 | "language": "python", 76 | "name": "python3" 77 | }, 78 | "language_info": { 79 | "codemirror_mode": { 80 | "name": "ipython", 81 | "version": 3 82 | }, 83 | "file_extension": ".py", 84 | "mimetype": "text/x-python", 85 | "name": "python", 86 | "nbconvert_exporter": "python", 87 | "pygments_lexer": "ipython3", 88 | "version": "3.8.5" 89 | } 90 | }, 91 | "nbformat": 4, 92 | "nbformat_minor": 4 93 | } 94 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/Assignment (10).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Row Wise Sum\n" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "p=int(input())\n", 17 | "for i in range(p):\n", 18 | " str=input().split()\n", 19 | " n,m=int(str[0]),int(str[1])\n", 20 | " arr=[]\n", 21 | " for i in range(n):\n", 22 | " b=input().split()\n", 23 | " arrr=[int(x) for x in b]\n", 24 | " print(sum(arrr),end=\" \")\n", 25 | " print()" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "# Largest Row or Column" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "from sys import stdin\n", 42 | "MIN_VALUE=-2147483648\n", 43 | "def findLargest(arr, nRows, mCols):\n", 44 | " #Your code goes here\n", 45 | " isRow =True\n", 46 | " largestSum=MIN_VALUE\n", 47 | " num=0\n", 48 | " for i in range(nRows):\n", 49 | " rowSum=0\n", 50 | " for j in range(mCols):\n", 51 | " rowSum+=arr[i][j]\n", 52 | " if rowSum>largestSum:\n", 53 | " largestSum=rowSum\n", 54 | " num=i\n", 55 | " for j in range(mCols):\n", 56 | " colSum=0\n", 57 | " for i in range(nRows):\n", 58 | " colSum+=arr[i][j]\n", 59 | " if colSum>largestSum:\n", 60 | " largestSum=colSum\n", 61 | " num=j\n", 62 | " isRow=False\n", 63 | " if isRow:\n", 64 | " print(\"row \"+str(num)+\" \"+str(largestSum))\n", 65 | " else:\n", 66 | " print(\"column \"+str(num)+\" \"+str(largestSum))\n", 67 | "#Taking Input Using Fast I/O\n", 68 | "def take2DInput() :\n", 69 | " li = stdin.readline().rstrip().split(\" \")\n", 70 | " nRows = int(li[0])\n", 71 | " mCols = int(li[1])\n", 72 | " \n", 73 | " if nRows == 0 :\n", 74 | " return list(), 0, 0\n", 75 | " \n", 76 | " mat = [list(map(int, input().strip().split(\" \"))) for row in range(nRows)]\n", 77 | " return mat, nRows, mCols\n", 78 | "\n", 79 | "\n", 80 | "#main\n", 81 | "t = int(stdin.readline().rstrip())\n", 82 | "\n", 83 | "while t > 0 :\n", 84 | "\n", 85 | " mat, nRows, mCols = take2DInput()\n", 86 | " findLargest(mat, nRows, mCols)\n", 87 | "\n", 88 | " t -= 1" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "# Wave Print\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": null, 101 | "metadata": {}, 102 | "outputs": [], 103 | "source": [ 104 | "from sys import stdin\n", 105 | "\n", 106 | "def wavePrint(mat, nrows, mcols):\n", 107 | " if nrows==0:\n", 108 | " return\n", 109 | " \n", 110 | " for j in range(mcols):\n", 111 | " if j%2==0:\n", 112 | " for i in range(nrows):\n", 113 | " print(mat[i][j],end=\" \")\n", 114 | " \n", 115 | " else:\n", 116 | " for i in range((nrows-1),-1,-1):\n", 117 | " print(mat[i][j],end=\" \")\n", 118 | "\n", 119 | "\n", 120 | "def take2DInput() :\n", 121 | " li = stdin.readline().rstrip().split(\" \")\n", 122 | " nRows = int(li[0])\n", 123 | " mCols = int(li[1])\n", 124 | " \n", 125 | " if nRows == 0 :\n", 126 | " return list(), 0, 0\n", 127 | " \n", 128 | " mat = [list(map(int, input().strip().split(\" \"))) for row in range(nRows)]\n", 129 | " return mat, nRows, mCols\n", 130 | "\n", 131 | "\n", 132 | "t = int(stdin.readline().rstrip())\n", 133 | "\n", 134 | "while t > 0 :\n", 135 | "\n", 136 | " mat, nRows, mCols = take2DInput()\n", 137 | " wavePrint(mat, nRows, mCols)\n", 138 | " print()\n", 139 | "\n", 140 | " t -= 1" 141 | ] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "metadata": {}, 146 | "source": [ 147 | "# Spiral Print" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "from sys import stdin\n", 157 | "\n", 158 | "def spiralPrint(twoDArr, nRows, mCols):\n", 159 | " top=0\n", 160 | " bottom=row-1\n", 161 | " left=0\n", 162 | " right=col-1\n", 163 | " direction=0\n", 164 | "\n", 165 | " while (top<=bottom) and (left<=right):\n", 166 | "\n", 167 | " if (direction==0):\n", 168 | " for i in range(left,right+1):\n", 169 | " print(twoDArr[top][i],end=\" \")\n", 170 | " top+=1\n", 171 | " direction=1\n", 172 | "\n", 173 | " elif (direction==1):\n", 174 | " for i in range(top,bottom+1):\n", 175 | " print(twoDArr[i][right],end=\" \")\n", 176 | " right-=1\n", 177 | " direction=2\n", 178 | "\n", 179 | " elif (direction==2):\n", 180 | " for i in range(right,left-1,-1):\n", 181 | " print(twoDArr[bottom][i],end=\" \")\n", 182 | " bottom-=1\n", 183 | " direction=3\n", 184 | "\n", 185 | " elif (direction==3):\n", 186 | " for i in range(bottom,top-1,-1):\n", 187 | " print(twoDArr[i][left],end=\" \")\n", 188 | " left+=1\n", 189 | " direction=0\n", 190 | "\n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | "for i in range(int(input())):\n", 196 | " l=[int(i) for i in input().strip().split(\" \")]\n", 197 | " row,col = l[0],l[1]\n", 198 | " arr=[[int(i) for i in input().split()] for j in range(row)]\n", 199 | " spiralPrint(arr,row,col)\n", 200 | " print()" 201 | ] 202 | } 203 | ], 204 | "metadata": { 205 | "kernelspec": { 206 | "display_name": "Python 3", 207 | "language": "python", 208 | "name": "python3" 209 | }, 210 | "language_info": { 211 | "codemirror_mode": { 212 | "name": "ipython", 213 | "version": 3 214 | }, 215 | "file_extension": ".py", 216 | "mimetype": "text/x-python", 217 | "name": "python", 218 | "nbconvert_exporter": "python", 219 | "pygments_lexer": "ipython3", 220 | "version": "3.8.5" 221 | } 222 | }, 223 | "nbformat": 4, 224 | "nbformat_minor": 4 225 | } 226 | -------------------------------------------------------------------------------- /10. Two Dimensional Lists/Two Dimensional Lists.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/10. Two Dimensional Lists/Two Dimensional Lists.pdf -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/01. Tuples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "(1, 2)\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "a = (1,2)\n", 18 | "print(a)" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 2, 24 | "metadata": { 25 | "scrolled": true 26 | }, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "print(type(a))" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 3, 43 | "metadata": { 44 | "scrolled": true 45 | }, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "1\n", 52 | "2\n", 53 | "(1, 2)\n", 54 | "\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "b,c = 1,2\n", 60 | "\n", 61 | "print(b)\n", 62 | "print(c)\n", 63 | "\n", 64 | "e = 1,2\n", 65 | "\n", 66 | "print(e)\n", 67 | "print(type(e))" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 6, 73 | "metadata": { 74 | "scrolled": true 75 | }, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "1" 81 | ] 82 | }, 83 | "execution_count": 6, 84 | "metadata": {}, 85 | "output_type": "execute_result" 86 | } 87 | ], 88 | "source": [ 89 | "e = 1,2\n", 90 | "e[0]" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 8, 96 | "metadata": { 97 | "scrolled": true 98 | }, 99 | "outputs": [ 100 | { 101 | "data": { 102 | "text/plain": [ 103 | "2" 104 | ] 105 | }, 106 | "execution_count": 8, 107 | "metadata": {}, 108 | "output_type": "execute_result" 109 | } 110 | ], 111 | "source": [ 112 | "e[1]" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 9, 118 | "metadata": { 119 | "scrolled": true 120 | }, 121 | "outputs": [ 122 | { 123 | "ename": "IndexError", 124 | "evalue": "tuple index out of range", 125 | "output_type": "error", 126 | "traceback": [ 127 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 128 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 129 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0me\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 130 | "\u001b[1;31mIndexError\u001b[0m: tuple index out of range" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "e[2]" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 10, 141 | "metadata": { 142 | "scrolled": true 143 | }, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "2" 149 | ] 150 | }, 151 | "execution_count": 10, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "e[-1]" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 11, 163 | "metadata": { 164 | "scrolled": true 165 | }, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "1" 171 | ] 172 | }, 173 | "execution_count": 11, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "e[-2]" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 14, 185 | "metadata": { 186 | "scrolled": true 187 | }, 188 | "outputs": [ 189 | { 190 | "name": "stdout", 191 | "output_type": "stream", 192 | "text": [ 193 | "(4, 5, 6)\n", 194 | "(1, 2, 3)\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "f =(1,2,3,4,5,6)\n", 200 | "\n", 201 | "print(f[3:])\n", 202 | "\n", 203 | "print(f[:3])" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 15, 209 | "metadata": { 210 | "scrolled": true 211 | }, 212 | "outputs": [ 213 | { 214 | "ename": "TypeError", 215 | "evalue": "'tuple' object does not support item assignment", 216 | "output_type": "error", 217 | "traceback": [ 218 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 219 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 220 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m34\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 221 | "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 222 | ] 223 | } 224 | ], 225 | "source": [ 226 | " f[4]=34" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 16, 232 | "metadata": {}, 233 | "outputs": [], 234 | "source": [ 235 | "del f" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 17, 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "ename": "NameError", 245 | "evalue": "name 'f' is not defined", 246 | "output_type": "error", 247 | "traceback": [ 248 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 249 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 250 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 251 | "\u001b[1;31mNameError\u001b[0m: name 'f' is not defined" 252 | ] 253 | } 254 | ], 255 | "source": [ 256 | "f" 257 | ] 258 | } 259 | ], 260 | "metadata": { 261 | "kernelspec": { 262 | "display_name": "Python 3", 263 | "language": "python", 264 | "name": "python3" 265 | }, 266 | "language_info": { 267 | "codemirror_mode": { 268 | "name": "ipython", 269 | "version": 3 270 | }, 271 | "file_extension": ".py", 272 | "mimetype": "text/x-python", 273 | "name": "python", 274 | "nbconvert_exporter": "python", 275 | "pygments_lexer": "ipython3", 276 | "version": "3.8.5" 277 | } 278 | }, 279 | "nbformat": 4, 280 | "nbformat_minor": 4 281 | } 282 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/03. Variable length Input and Output.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "3" 14 | ] 15 | }, 16 | "execution_count": 2, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "def sum(a,b):\n", 23 | " return a+b\n", 24 | "\n", 25 | "sum (1,2)" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 3, 31 | "metadata": { 32 | "scrolled": true 33 | }, 34 | "outputs": [ 35 | { 36 | "ename": "TypeError", 37 | "evalue": "sum() takes 2 positional arguments but 3 were given", 38 | "output_type": "error", 39 | "traceback": [ 40 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 41 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 42 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 43 | "\u001b[1;31mTypeError\u001b[0m: sum() takes 2 positional arguments but 3 were given" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "sum(1,2,3)" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 14, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "def sum(a,b,*more):\n", 58 | " print(a)\n", 59 | " print(b)\n", 60 | " print(type(more))\n", 61 | " print(more)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 15, 67 | "metadata": { 68 | "scrolled": true 69 | }, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "1\n", 76 | "2\n", 77 | "\n", 78 | "(3, 4, 5)\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "sum(1,2,3,4,5) " 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 25, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "def ans(a,b,*more):\n", 93 | " ans =a+b\n", 94 | " for i in more:\n", 95 | " ans = ans+i\n", 96 | " return ans" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 28, 102 | "metadata": { 103 | "scrolled": false 104 | }, 105 | "outputs": [ 106 | { 107 | "data": { 108 | "text/plain": [ 109 | "70" 110 | ] 111 | }, 112 | "execution_count": 28, 113 | "metadata": {}, 114 | "output_type": "execute_result" 115 | } 116 | ], 117 | "source": [ 118 | "ans (1,2,3,5,7,2,1,2,7,7,3,3,7,3,7,3,7)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 37, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "def sum_diff(a,b):\n", 128 | " return a+b,a-b" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 38, 134 | "metadata": { 135 | "scrolled": true 136 | }, 137 | "outputs": [ 138 | { 139 | "data": { 140 | "text/plain": [ 141 | "(5, 3)" 142 | ] 143 | }, 144 | "execution_count": 38, 145 | "metadata": {}, 146 | "output_type": "execute_result" 147 | } 148 | ], 149 | "source": [ 150 | "c = sum_diff(4,1)\n", 151 | "c" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 39, 157 | "metadata": { 158 | "scrolled": true 159 | }, 160 | "outputs": [ 161 | { 162 | "name": "stdout", 163 | "output_type": "stream", 164 | "text": [ 165 | "5\n", 166 | "3\n" 167 | ] 168 | } 169 | ], 170 | "source": [ 171 | "d,e = sum_diff(4,1)\n", 172 | "print(d)\n", 173 | "print(e)" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 40, 179 | "metadata": {}, 180 | "outputs": [], 181 | "source": [ 182 | "def sum_diff1(a,b):\n", 183 | " return a+b,a-b,a*b" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 41, 189 | "metadata": { 190 | "scrolled": true 191 | }, 192 | "outputs": [ 193 | { 194 | "ename": "ValueError", 195 | "evalue": "too many values to unpack (expected 2)", 196 | "output_type": "error", 197 | "traceback": [ 198 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 199 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 200 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0md\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0me\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msum_diff1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0md\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0me\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 201 | "\u001b[1;31mValueError\u001b[0m: too many values to unpack (expected 2)" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "d,e = sum_diff1(4,1)\n", 207 | "print(d)\n", 208 | "print(e)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 43, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "(5, 3, 4)\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "d= sum_diff1(4,1)\n", 226 | "print(d)" 227 | ] 228 | } 229 | ], 230 | "metadata": { 231 | "kernelspec": { 232 | "display_name": "Python 3", 233 | "language": "python", 234 | "name": "python3" 235 | }, 236 | "language_info": { 237 | "codemirror_mode": { 238 | "name": "ipython", 239 | "version": 3 240 | }, 241 | "file_extension": ".py", 242 | "mimetype": "text/x-python", 243 | "name": "python", 244 | "nbconvert_exporter": "python", 245 | "pygments_lexer": "ipython3", 246 | "version": "3.8.5" 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 4 251 | } 252 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/04.Intro Dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "dict" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "a ={}\n", 23 | "type(a)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": { 30 | "scrolled": true 31 | }, 32 | "outputs": [ 33 | { 34 | "data": { 35 | "text/plain": [ 36 | "{'the': 2, 'a': 5, 100: 'abc'}" 37 | ] 38 | }, 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "output_type": "execute_result" 42 | } 43 | ], 44 | "source": [ 45 | "a ={\"the\":2,\"a\":5,100:\"abc\"}\n", 46 | "a" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 3, 52 | "metadata": { 53 | "scrolled": true 54 | }, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/plain": [ 59 | "3" 60 | ] 61 | }, 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "output_type": "execute_result" 65 | } 66 | ], 67 | "source": [ 68 | "len(a)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 5, 74 | "metadata": { 75 | "scrolled": true 76 | }, 77 | "outputs": [ 78 | { 79 | "data": { 80 | "text/plain": [ 81 | "{'the': 2, 'a': 5, 100: 'abc'}" 82 | ] 83 | }, 84 | "execution_count": 5, 85 | "metadata": {}, 86 | "output_type": "execute_result" 87 | } 88 | ], 89 | "source": [ 90 | "b = a.copy()\n", 91 | "b" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 8, 97 | "metadata": { 98 | "scrolled": true 99 | }, 100 | "outputs": [ 101 | { 102 | "data": { 103 | "text/plain": [ 104 | "{'the': 3, 'a': 10, 2: 3}" 105 | ] 106 | }, 107 | "execution_count": 8, 108 | "metadata": {}, 109 | "output_type": "execute_result" 110 | } 111 | ], 112 | "source": [ 113 | "c = dict([(\"the\",3),(\"a\",10),(2,3)])\n", 114 | "c" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 9, 120 | "metadata": { 121 | "scrolled": true 122 | }, 123 | "outputs": [ 124 | { 125 | "data": { 126 | "text/plain": [ 127 | "{'abc': None, 32: None, 4: None}" 128 | ] 129 | }, 130 | "execution_count": 9, 131 | "metadata": {}, 132 | "output_type": "execute_result" 133 | } 134 | ], 135 | "source": [ 136 | "d = dict.fromkeys([\"abc\",32,4])\n", 137 | "d" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 10, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "{'abc': 10, 32: 10, 4: 10}" 149 | ] 150 | }, 151 | "execution_count": 10, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "d = dict.fromkeys([\"abc\",32,4],10)\n", 158 | "d" 159 | ] 160 | } 161 | ], 162 | "metadata": { 163 | "kernelspec": { 164 | "display_name": "Python 3", 165 | "language": "python", 166 | "name": "python3" 167 | }, 168 | "language_info": { 169 | "codemirror_mode": { 170 | "name": "ipython", 171 | "version": 3 172 | }, 173 | "file_extension": ".py", 174 | "mimetype": "text/x-python", 175 | "name": "python", 176 | "nbconvert_exporter": "python", 177 | "pygments_lexer": "ipython3", 178 | "version": "3.8.5" 179 | } 180 | }, 181 | "nbformat": 4, 182 | "nbformat_minor": 4 183 | } 184 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/05. Access & Looping element in Dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "text/plain": [ 11 | "{1: 2, 3: 4, 'list': [1, 2, 3], 'dict': {1, 2}}" 12 | ] 13 | }, 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "output_type": "execute_result" 17 | } 18 | ], 19 | "source": [ 20 | "a = {1:2,3:4,\"list\":[1,2,3],\"dict\":{1,2}}\n", 21 | "a" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/plain": [ 32 | "2" 33 | ] 34 | }, 35 | "execution_count": 3, 36 | "metadata": {}, 37 | "output_type": "execute_result" 38 | } 39 | ], 40 | "source": [ 41 | "a[1]" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 5, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "data": { 51 | "text/plain": [ 52 | "4" 53 | ] 54 | }, 55 | "execution_count": 5, 56 | "metadata": {}, 57 | "output_type": "execute_result" 58 | } 59 | ], 60 | "source": [ 61 | "a[3]" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 6, 67 | "metadata": { 68 | "scrolled": true 69 | }, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "2" 75 | ] 76 | }, 77 | "execution_count": 6, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "a.get(1)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 7, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "a.get(2)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 8, 98 | "metadata": { 99 | "scrolled": true 100 | }, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "None\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "print(a.get(2))" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 10, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "data": { 121 | "text/plain": [ 122 | "dict_keys([1, 3, 'list', 'dict'])" 123 | ] 124 | }, 125 | "execution_count": 10, 126 | "metadata": {}, 127 | "output_type": "execute_result" 128 | } 129 | ], 130 | "source": [ 131 | "a.keys()" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 11, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "data": { 141 | "text/plain": [ 142 | "dict_values([2, 4, [1, 2, 3], {1, 2}])" 143 | ] 144 | }, 145 | "execution_count": 11, 146 | "metadata": {}, 147 | "output_type": "execute_result" 148 | } 149 | ], 150 | "source": [ 151 | "a.values()" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 12, 157 | "metadata": { 158 | "scrolled": true 159 | }, 160 | "outputs": [ 161 | { 162 | "data": { 163 | "text/plain": [ 164 | "dict_items([(1, 2), (3, 4), ('list', [1, 2, 3]), ('dict', {1, 2})])" 165 | ] 166 | }, 167 | "execution_count": 12, 168 | "metadata": {}, 169 | "output_type": "execute_result" 170 | } 171 | ], 172 | "source": [ 173 | "a.items()" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 14, 179 | "metadata": { 180 | "scrolled": true 181 | }, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "1\n", 188 | "3\n", 189 | "list\n", 190 | "dict\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "for i in a:\n", 196 | " print(i)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 16, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "1 2\n", 209 | "3 4\n", 210 | "list [1, 2, 3]\n", 211 | "dict {1, 2}\n" 212 | ] 213 | } 214 | ], 215 | "source": [ 216 | "for i in a:\n", 217 | " print(i,a[i])" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 17, 223 | "metadata": { 224 | "scrolled": true 225 | }, 226 | "outputs": [ 227 | { 228 | "name": "stdout", 229 | "output_type": "stream", 230 | "text": [ 231 | "2\n", 232 | "4\n", 233 | "[1, 2, 3]\n", 234 | "{1, 2}\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "for i in a.values():\n", 240 | " print(i)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 18, 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "data": { 250 | "text/plain": [ 251 | "True" 252 | ] 253 | }, 254 | "execution_count": 18, 255 | "metadata": {}, 256 | "output_type": "execute_result" 257 | } 258 | ], 259 | "source": [ 260 | "\"list\" in a" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 19, 266 | "metadata": {}, 267 | "outputs": [ 268 | { 269 | "data": { 270 | "text/plain": [ 271 | "False" 272 | ] 273 | }, 274 | "execution_count": 19, 275 | "metadata": {}, 276 | "output_type": "execute_result" 277 | } 278 | ], 279 | "source": [ 280 | "'li' in a" 281 | ] 282 | } 283 | ], 284 | "metadata": { 285 | "kernelspec": { 286 | "display_name": "Python 3", 287 | "language": "python", 288 | "name": "python3" 289 | }, 290 | "language_info": { 291 | "codemirror_mode": { 292 | "name": "ipython", 293 | "version": 3 294 | }, 295 | "file_extension": ".py", 296 | "mimetype": "text/x-python", 297 | "name": "python", 298 | "nbconvert_exporter": "python", 299 | "pygments_lexer": "ipython3", 300 | "version": "3.8.5" 301 | } 302 | }, 303 | "nbformat": 4, 304 | "nbformat_minor": 4 305 | } 306 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/06. Adding Or Removing Data In Dictionary.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "{1: 2, 3: 4, 'list': [1, 2, 3], 'dict': {1, 2}}" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "a = {1:2,3:4,\"list\":[1,2,3],\"dict\":{1,2}}\n", 23 | "a" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "a['t'] = (1,2,3)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "{1: 2, 3: 4, 'list': [1, 2, 3], 'dict': {1, 2}, 't': (1, 2, 3)}" 44 | ] 45 | }, 46 | "execution_count": 3, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "a" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "metadata": {}, 59 | "outputs": [], 60 | "source": [ 61 | "a[1]=10" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 5, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "{1: 10, 3: 4, 'list': [1, 2, 3], 'dict': {1, 2}, 't': (1, 2, 3)}" 73 | ] 74 | }, 75 | "execution_count": 5, 76 | "metadata": {}, 77 | "output_type": "execute_result" 78 | } 79 | ], 80 | "source": [ 81 | "a" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 6, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "b = {3:5,\"the\":4,2:100}" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 7, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "a.update(b)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 8, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "{1: 10,\n", 111 | " 3: 5,\n", 112 | " 'list': [1, 2, 3],\n", 113 | " 'dict': {1, 2},\n", 114 | " 't': (1, 2, 3),\n", 115 | " 'the': 4,\n", 116 | " 2: 100}" 117 | ] 118 | }, 119 | "execution_count": 8, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "a" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 9, 131 | "metadata": { 132 | "scrolled": true 133 | }, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "(1, 2, 3)" 139 | ] 140 | }, 141 | "execution_count": 9, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "a.pop(\"t\")" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 10, 153 | "metadata": { 154 | "scrolled": true 155 | }, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "{1: 10, 3: 5, 'list': [1, 2, 3], 'dict': {1, 2}, 'the': 4, 2: 100}" 161 | ] 162 | }, 163 | "execution_count": 10, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "a" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 12, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "del a[1]" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 13, 184 | "metadata": { 185 | "scrolled": true 186 | }, 187 | "outputs": [ 188 | { 189 | "data": { 190 | "text/plain": [ 191 | "{3: 5, 'list': [1, 2, 3], 'dict': {1, 2}, 'the': 4, 2: 100}" 192 | ] 193 | }, 194 | "execution_count": 13, 195 | "metadata": {}, 196 | "output_type": "execute_result" 197 | } 198 | ], 199 | "source": [ 200 | "a" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 14, 206 | "metadata": {}, 207 | "outputs": [], 208 | "source": [ 209 | "a.clear()" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 15, 215 | "metadata": { 216 | "scrolled": true 217 | }, 218 | "outputs": [ 219 | { 220 | "data": { 221 | "text/plain": [ 222 | "{}" 223 | ] 224 | }, 225 | "execution_count": 15, 226 | "metadata": {}, 227 | "output_type": "execute_result" 228 | } 229 | ], 230 | "source": [ 231 | "a" 232 | ] 233 | }, 234 | { 235 | "cell_type": "code", 236 | "execution_count": 16, 237 | "metadata": {}, 238 | "outputs": [], 239 | "source": [ 240 | "del a" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 17, 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "ename": "NameError", 250 | "evalue": "name 'a' is not defined", 251 | "output_type": "error", 252 | "traceback": [ 253 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 254 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 255 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 256 | "\u001b[1;31mNameError\u001b[0m: name 'a' is not defined" 257 | ] 258 | } 259 | ], 260 | "source": [ 261 | "a" 262 | ] 263 | } 264 | ], 265 | "metadata": { 266 | "kernelspec": { 267 | "display_name": "Python 3", 268 | "language": "python", 269 | "name": "python3" 270 | }, 271 | "language_info": { 272 | "codemirror_mode": { 273 | "name": "ipython", 274 | "version": 3 275 | }, 276 | "file_extension": ".py", 277 | "mimetype": "text/x-python", 278 | "name": "python", 279 | "nbconvert_exporter": "python", 280 | "pygments_lexer": "ipython3", 281 | "version": "3.8.5" 282 | } 283 | }, 284 | "nbformat": 4, 285 | "nbformat_minor": 4 286 | } 287 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/07. Print All Words With Frequency K.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "scrolled": true 8 | }, 9 | "outputs": [ 10 | { 11 | "data": { 12 | "text/plain": [ 13 | "'This is word string having many many word'" 14 | ] 15 | }, 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "output_type": "execute_result" 19 | } 20 | ], 21 | "source": [ 22 | "s =\"This is word string having many many word\"\n", 23 | "s" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 9, 29 | "metadata": { 30 | "scrolled": true 31 | }, 32 | "outputs": [ 33 | { 34 | "data": { 35 | "text/plain": [ 36 | "['This', 'is', 'word', 'string', 'having', 'many', 'many', 'word']" 37 | ] 38 | }, 39 | "execution_count": 9, 40 | "metadata": {}, 41 | "output_type": "execute_result" 42 | } 43 | ], 44 | "source": [ 45 | "words = s.split()\n", 46 | "words" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 8, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "{'This': 1, 'is': 1, 'word': 2, 'string': 1, 'having': 1, 'many': 2}" 58 | ] 59 | }, 60 | "execution_count": 8, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "d={}\n", 67 | "for w in words:\n", 68 | " if w in d:\n", 69 | " d[w]=d[w]+1\n", 70 | " else:\n", 71 | " d[w]=1\n", 72 | "d" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 10, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "{'This': 1, 'is': 1, 'word': 2, 'string': 1, 'having': 1, 'many': 2}" 84 | ] 85 | }, 86 | "execution_count": 10, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "d = {}\n", 93 | "for w in words:\n", 94 | " d[w]=d.get(w,0)+1\n", 95 | " \n", 96 | "d" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 13, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "name": "stdout", 106 | "output_type": "stream", 107 | "text": [ 108 | "word\n", 109 | "many\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "for w in d:\n", 115 | " k = 2\n", 116 | " if d[w]==k:\n", 117 | " print(w)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 14, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "def printKFreqWords(s,k):\n", 127 | " words = s.split()\n", 128 | " d={}\n", 129 | " for w in words:\n", 130 | " d[w]=d.get(w,0)+1\n", 131 | " for w in d:\n", 132 | " if d[w] ==k:\n", 133 | " print(w)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 18, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "name": "stdout", 143 | "output_type": "stream", 144 | "text": [ 145 | "This\n", 146 | "is\n", 147 | "string\n", 148 | "having\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "printKFreqWords(s,1)" 154 | ] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "Python 3", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.8.5" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 4 178 | } 179 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/10. sum of all unique numbers in list.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 5, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "a = {1,2,3,1,3}" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 6, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "3" 21 | ] 22 | }, 23 | "execution_count": 6, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "len(a)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 7, 35 | "metadata": {}, 36 | "outputs": [], 37 | "source": [ 38 | "a.add(2)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 8, 44 | "metadata": { 45 | "scrolled": true 46 | }, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "{1, 2, 3}" 52 | ] 53 | }, 54 | "execution_count": 8, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "a" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 10, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "z = set()" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 11, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/plain": [ 80 | "set" 81 | ] 82 | }, 83 | "execution_count": 11, 84 | "metadata": {}, 85 | "output_type": "execute_result" 86 | } 87 | ], 88 | "source": [ 89 | "type(z)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 12, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "def sumUnique(l):\n", 99 | " s = set()\n", 100 | " for i in l:\n", 101 | " s.add(i)\n", 102 | " sum = 0\n", 103 | " for i in s:\n", 104 | " sum = sum + i\n", 105 | " return sum " 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 13, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "data": { 115 | "text/plain": [ 116 | "15" 117 | ] 118 | }, 119 | "execution_count": 13, 120 | "metadata": {}, 121 | "output_type": "execute_result" 122 | } 123 | ], 124 | "source": [ 125 | "sumUnique([1,2,3,4,4,3,2,1,5,5])" 126 | ] 127 | } 128 | ], 129 | "metadata": { 130 | "kernelspec": { 131 | "display_name": "Python 3", 132 | "language": "python", 133 | "name": "python3" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.8.5" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 4 150 | } 151 | -------------------------------------------------------------------------------- /11. Tuples, Dictionary And Sets/Tuples, Dictionaries and Sets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/11. Tuples, Dictionary And Sets/Tuples, Dictionaries and Sets.pdf -------------------------------------------------------------------------------- /Certificate/Coding Ninjas -Introduction to Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamvaibhavsingh09/Introduction-to-Python-CodingNinjas/6a466646fc7bf963c137d3c4b10296bff2b51b9e/Certificate/Coding Ninjas -Introduction to Python.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction-to-Python-CodingNinjas 2 | Phase 1 : Ninja Data Scientist Career Track. 3 | 4 | 1. Introduction to Python 5 | 2. Conditionals and Loops 6 | 3. Patterns 1 7 | 4. Patterns 2 8 | 5. More On Loops 9 | 6. Functions 10 | 7. Arrays and Lists 11 | 8. Searching and Sorting 12 | 9. Strings 13 | 10. Two Dimensional Lists 14 | 11. Tuples, Dictionaries and Sets 15 | --------------------------------------------------------------------------------