├── .gitignore ├── .ipynb_checkpoints ├── 10_Lists-checkpoint.ipynb ├── 11_Lists Functions and Methods-checkpoint.ipynb ├── 12_Strings-checkpoint.ipynb ├── 13_Strings Methods-checkpoint.ipynb ├── 14_For Loop-checkpoint.ipynb ├── 15_For Loop questions loop else-checkpoint.ipynb ├── 16_Functions-checkpoint.ipynb ├── 17_Functions-checkpoint.ipynb ├── 18_Functions-checkpoint.ipynb ├── 19_Dictionary-checkpoint.ipynb ├── 1_Python Introduction-checkpoint.ipynb ├── 20_Sets-checkpoint.ipynb ├── 21_Tuples-checkpoint.ipynb ├── 22_Tuples part 2-checkpoint.ipynb ├── 23_Object Oriented Programming-checkpoint.ipynb ├── 24_Object Oriented Programming-checkpoint.ipynb ├── 25_Object Oriented Programming-checkpoint.ipynb ├── 26_Object Oriented Programming-checkpoint.ipynb ├── 27_Object Oriented Programming-checkpoint.ipynb ├── 28_Python File Handling-checkpoint.ipynb ├── 29_30_Exception Handling-checkpoint.ipynb ├── 29_Python File Handling-checkpoint.ipynb ├── 2_Operators-checkpoint.ipynb ├── 31_Exception Handling-checkpoint.ipynb ├── 32_Regular expression-checkpoint.ipynb ├── 33_Modules Inbuild-checkpoint.ipynb ├── 35_Python Stack-checkpoint.ipynb ├── 36_Queue and Linear Searching-checkpoint.ipynb ├── 3_Operators Bitwise-checkpoint.ipynb ├── 41_NumPy-checkpoint.ipynb ├── 42_Pandas-checkpoint.ipynb ├── 43_Matplotlib-checkpoint.ipynb ├── 4_Conditional Statements-checkpoint.ipynb ├── 5_While Loop-checkpoint.ipynb ├── 6_While Loop Logic building-checkpoint.ipynb ├── 7_While Loop Logical Questions-checkpoint.ipynb ├── 8_While Loop Break Continue-checkpoint.ipynb └── 9_While Loop Nested-checkpoint.ipynb ├── 10_Lists.ipynb ├── 11_Lists Functions and Methods.ipynb ├── 12_Strings.ipynb ├── 13_Strings Methods.ipynb ├── 14_For Loop.ipynb ├── 15_For Loop questions loop else.ipynb ├── 16_Functions.ipynb ├── 17_Functions.ipynb ├── 18_Functions.ipynb ├── 19_Dictionary.ipynb ├── 1_Python Introduction.ipynb ├── 20_Sets.ipynb ├── 21_Tuples.ipynb ├── 22_Tuples part 2.ipynb ├── 23_Object Oriented Programming.ipynb ├── 24_Object Oriented Programming.ipynb ├── 25_Object Oriented Programming.ipynb ├── 26_Object Oriented Programming.ipynb ├── 27_Object Oriented Programming.ipynb ├── 28_Python File Handling.ipynb ├── 29_Python File Handling.ipynb ├── 2_Operators.ipynb ├── 30_Exception Handling.ipynb ├── 31_Exception Handling.ipynb ├── 32_Regular expression.ipynb ├── 33_Modules Inbuild.ipynb ├── 34_Packages ├── __pycache__ │ └── index.cpython-37.pyc ├── app.py ├── index.py └── mypackage │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── goa.cpython-37.pyc │ └── indore.cpython-37.pyc │ ├── goa.py │ └── indore.py ├── 35_Python Stack.ipynb ├── 36_Queue and Linear Searching.ipynb ├── 37_Virtual Environment and Scrapping └── main.py ├── 38_Flask Framework └── 1_Flask Basics │ ├── application.py │ ├── static │ └── css │ │ └── style.css │ └── templates │ └── index.html ├── 39_40_Python and MongoDB Database └── app.py ├── 3_Operators Bitwise.ipynb ├── 41_NumPy.ipynb ├── 42_Pandas.ipynb ├── 43_Matplotlib.ipynb ├── 4_Conditional Statements.ipynb ├── 5_While Loop.ipynb ├── 6_While Loop Logic building.ipynb ├── 7_While Loop Logical Questions.ipynb ├── 8_While Loop Break Continue.ipynb ├── 9_While Loop Nested.ipynb ├── Python Roadmap 2022.pdf ├── README.md ├── goa.xlsx ├── hello.py ├── images └── pythoncoreheader.png ├── indore_weather.csv ├── mumbai.txt ├── nyc_weather.csv ├── queens.txt ├── script.py └── student.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ -------------------------------------------------------------------------------- /.ipynb_checkpoints/1_Python Introduction-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 1 | Introduction and Basics\n", 8 | "\n", 9 | "First session Theory\n", 10 | "\n", 11 | "1. Installation\n", 12 | "2. Python Org, Python 3\n", 13 | "3. Variables\n", 14 | "4. Print function\n", 15 | "5. Input from user\n", 16 | "6. Data Types\n", 17 | "7. Type Conversion\n", 18 | "8. First Program\n" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "Hello World\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "print(\"Hello World\")" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 2, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "Hello\n", 48 | "World\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "# \\n - new line character\n", 54 | "\n", 55 | "print(\"Hello\\nWorld\")" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 3, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Hello\tWorld\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# \\t - horizontal tab\n", 73 | "\n", 74 | "print(\"Hello\\tWorld\")" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "## Basic Questions" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "name\n", 91 | " college\n", 92 | " city" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 4, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "Himanshu\n", 105 | "\tDAVV\n", 106 | "\t\tIndore\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "print(\"Himanshu\\n\\tDAVV\\n\\t\\tIndore\")" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "*\n", 121 | "**\n", 122 | "***" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 5, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "name": "stdout", 132 | "output_type": "stream", 133 | "text": [ 134 | "*\n", 135 | "**\n", 136 | "***\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "print(\"*\\n**\\n***\")" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | " *\n", 151 | "* *\n", 152 | " *" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 7, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | " *\n", 165 | "*\t*\n", 166 | " *\n" 167 | ] 168 | } 169 | ], 170 | "source": [ 171 | "print(\" *\\n*\\t*\\n *\")" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "# Variables" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 8, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "10\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "a = 10\n", 196 | "\n", 197 | "print(a)" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 9, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "name": "stdout", 207 | "output_type": "stream", 208 | "text": [ 209 | "10.5\n" 210 | ] 211 | } 212 | ], 213 | "source": [ 214 | "b = 10.5\n", 215 | "\n", 216 | "print(b)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 10, 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "name": "stdout", 226 | "output_type": "stream", 227 | "text": [ 228 | "Indore\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "c = \"Indore\"\n", 234 | "\n", 235 | "print(c)" 236 | ] 237 | }, 238 | { 239 | "cell_type": "markdown", 240 | "metadata": {}, 241 | "source": [ 242 | "## type function" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 12, 248 | "metadata": {}, 249 | "outputs": [ 250 | { 251 | "name": "stdout", 252 | "output_type": "stream", 253 | "text": [ 254 | "10\n", 255 | "\n" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "print(a)\n", 261 | "\n", 262 | "print(type(a))" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 14, 268 | "metadata": {}, 269 | "outputs": [ 270 | { 271 | "name": "stdout", 272 | "output_type": "stream", 273 | "text": [ 274 | "10.5\n", 275 | "\n" 276 | ] 277 | } 278 | ], 279 | "source": [ 280 | "print(b)\n", 281 | "\n", 282 | "print(type(b))" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 16, 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "name": "stdout", 292 | "output_type": "stream", 293 | "text": [ 294 | "Indore\n", 295 | "\n" 296 | ] 297 | } 298 | ], 299 | "source": [ 300 | "print(c)\n", 301 | "\n", 302 | "print(type(c))" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 17, 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "15\n", 315 | "10\n" 316 | ] 317 | } 318 | ], 319 | "source": [ 320 | "a = 10\n", 321 | "\n", 322 | "print(a + 5)\n", 323 | "\n", 324 | "print(a)" 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "metadata": {}, 330 | "source": [ 331 | "# User Input" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 18, 337 | "metadata": {}, 338 | "outputs": [ 339 | { 340 | "name": "stdout", 341 | "output_type": "stream", 342 | "text": [ 343 | "10\n", 344 | "10\n" 345 | ] 346 | } 347 | ], 348 | "source": [ 349 | "x = input()\n", 350 | "#x = 10\n", 351 | "\n", 352 | "print(x)" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": 20, 358 | "metadata": {}, 359 | "outputs": [ 360 | { 361 | "name": "stdout", 362 | "output_type": "stream", 363 | "text": [ 364 | "Enter Your Name: Himanshu\n", 365 | "Himanshu\n" 366 | ] 367 | } 368 | ], 369 | "source": [ 370 | "x = input(\"Enter Your Name: \")\n", 371 | "\n", 372 | "print(x)" 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 21, 378 | "metadata": {}, 379 | "outputs": [ 380 | { 381 | "name": "stdout", 382 | "output_type": "stream", 383 | "text": [ 384 | "Enter Your Name: Himanshu\n", 385 | "Hello Himanshu\n" 386 | ] 387 | } 388 | ], 389 | "source": [ 390 | "x = input(\"Enter Your Name: \")\n", 391 | "\n", 392 | "print(\"Hello\",x)" 393 | ] 394 | }, 395 | { 396 | "cell_type": "markdown", 397 | "metadata": {}, 398 | "source": [ 399 | "# First Program\n", 400 | "\n", 401 | "WAP to enter 2 numbers from user and print sum of them." 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": 22, 407 | "metadata": {}, 408 | "outputs": [ 409 | { 410 | "name": "stdout", 411 | "output_type": "stream", 412 | "text": [ 413 | "Enter 1st number: 10\n", 414 | "Enter 2nd number: 20\n", 415 | "1020\n" 416 | ] 417 | } 418 | ], 419 | "source": [ 420 | "a = input(\"Enter 1st number: \")\n", 421 | "b = input(\"Enter 2nd number: \")\n", 422 | "\n", 423 | "c = a + b\n", 424 | "\n", 425 | "print(c)" 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 23, 431 | "metadata": {}, 432 | "outputs": [ 433 | { 434 | "data": { 435 | "text/plain": [ 436 | "'1020'" 437 | ] 438 | }, 439 | "execution_count": 23, 440 | "metadata": {}, 441 | "output_type": "execute_result" 442 | } 443 | ], 444 | "source": [ 445 | "\"10\" + \"20\"" 446 | ] 447 | }, 448 | { 449 | "cell_type": "code", 450 | "execution_count": 25, 451 | "metadata": {}, 452 | "outputs": [ 453 | { 454 | "name": "stdout", 455 | "output_type": "stream", 456 | "text": [ 457 | "\n" 458 | ] 459 | } 460 | ], 461 | "source": [ 462 | "print(type(a))" 463 | ] 464 | }, 465 | { 466 | "cell_type": "markdown", 467 | "metadata": {}, 468 | "source": [ 469 | "# Type Casting" 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "execution_count": 26, 475 | "metadata": {}, 476 | "outputs": [ 477 | { 478 | "name": "stdout", 479 | "output_type": "stream", 480 | "text": [ 481 | "\n", 482 | "10\n", 483 | "\n" 484 | ] 485 | } 486 | ], 487 | "source": [ 488 | "a = 10.5\n", 489 | "print(type(a))\n", 490 | "\n", 491 | "b = int(a)\n", 492 | "\n", 493 | "print(b)\n", 494 | "print(type(b))" 495 | ] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": 27, 500 | "metadata": {}, 501 | "outputs": [ 502 | { 503 | "name": "stdout", 504 | "output_type": "stream", 505 | "text": [ 506 | "Enter 1st number: 10\n", 507 | "Enter 2nd number: 20\n", 508 | "30\n" 509 | ] 510 | } 511 | ], 512 | "source": [ 513 | "a = int(input(\"Enter 1st number: \"))\n", 514 | "b = int(input(\"Enter 2nd number: \"))\n", 515 | "\n", 516 | "c = a + b\n", 517 | "\n", 518 | "print(c)" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": 28, 524 | "metadata": {}, 525 | "outputs": [ 526 | { 527 | "name": "stdout", 528 | "output_type": "stream", 529 | "text": [ 530 | "Enter 1st number: 10\n", 531 | "Enter 2nd number: 20\n", 532 | "Addition = 30\n" 533 | ] 534 | } 535 | ], 536 | "source": [ 537 | "a = int(input(\"Enter 1st number: \"))\n", 538 | "b = int(input(\"Enter 2nd number: \"))\n", 539 | "\n", 540 | "c = a + b\n", 541 | "\n", 542 | "print(\"Addition =\",c)" 543 | ] 544 | }, 545 | { 546 | "cell_type": "code", 547 | "execution_count": null, 548 | "metadata": {}, 549 | "outputs": [], 550 | "source": [] 551 | } 552 | ], 553 | "metadata": { 554 | "kernelspec": { 555 | "display_name": "Python 3", 556 | "language": "python", 557 | "name": "python3" 558 | }, 559 | "language_info": { 560 | "codemirror_mode": { 561 | "name": "ipython", 562 | "version": 3 563 | }, 564 | "file_extension": ".py", 565 | "mimetype": "text/x-python", 566 | "name": "python", 567 | "nbconvert_exporter": "python", 568 | "pygments_lexer": "ipython3", 569 | "version": "3.7.6" 570 | } 571 | }, 572 | "nbformat": 4, 573 | "nbformat_minor": 4 574 | } 575 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/21_Tuples-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuple\n", 8 | "Tuples Basics\n", 9 | "\n", 10 | "Tuples Comprehensions / Slicing\n", 11 | "\n", 12 | "Tuple Functions\n", 13 | "\n", 14 | "Tuple Methods" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "(1, 2, 3, 'A')\n", 27 | "\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "t = (1,2,3,\"A\") # immutable\n", 33 | "\n", 34 | "print(t)\n", 35 | "\n", 36 | "print(type(t))" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "ename": "TypeError", 46 | "evalue": "'tuple' object does not support item assignment", 47 | "output_type": "error", 48 | "traceback": [ 49 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 50 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 51 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 52 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "t[0] = 10" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "1\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(t[0])" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "A\n" 87 | ] 88 | } 89 | ], 90 | "source": [ 91 | "print(t[3])" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "('one', 'two', 'three')\n", 104 | "\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "my = \"one\", \"two\", \"three\"\n", 110 | "\n", 111 | "print(my)\n", 112 | "\n", 113 | "print(type(my))" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "three\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "print(my[2])" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 8, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "()\n", 143 | "\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "t = ()\n", 149 | "\n", 150 | "print(t)\n", 151 | "\n", 152 | "print(type(t))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 11, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "10\n", 165 | "\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "t = (10)\n", 171 | "\n", 172 | "print(t)\n", 173 | "\n", 174 | "print(type(t))" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 12, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "(10,)\n", 187 | "\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "t = (10,)\n", 193 | "\n", 194 | "print(t)\n", 195 | "\n", 196 | "print(type(t))" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "# Tuple Unpacking" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "n = (1,2,3)\n", 213 | "\n", 214 | "a,b,c = n\n", 215 | "\n", 216 | "print" 217 | ] 218 | } 219 | ], 220 | "metadata": { 221 | "kernelspec": { 222 | "display_name": "Python 3", 223 | "language": "python", 224 | "name": "python3" 225 | }, 226 | "language_info": { 227 | "codemirror_mode": { 228 | "name": "ipython", 229 | "version": 3 230 | }, 231 | "file_extension": ".py", 232 | "mimetype": "text/x-python", 233 | "name": "python", 234 | "nbconvert_exporter": "python", 235 | "pygments_lexer": "ipython3", 236 | "version": "3.7.6" 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/22_Tuples part 2-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuple\n", 8 | "Tuples Basics\n", 9 | "\n", 10 | "Tuples Comprehensions / Slicing\n", 11 | "\n", 12 | "Tuple Functions\n", 13 | "\n", 14 | "Tuple Methods" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "(1, 2, 3, 'A')\n", 27 | "\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "t = (1,2,3,\"A\") # immutable\n", 33 | "\n", 34 | "print(t)\n", 35 | "\n", 36 | "print(type(t))" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "ename": "TypeError", 46 | "evalue": "'tuple' object does not support item assignment", 47 | "output_type": "error", 48 | "traceback": [ 49 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 50 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 51 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 52 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "t[0] = 10" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "1\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(t[0])" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "A\n" 87 | ] 88 | } 89 | ], 90 | "source": [ 91 | "print(t[3])" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "('one', 'two', 'three')\n", 104 | "\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "my = \"one\", \"two\", \"three\"\n", 110 | "\n", 111 | "print(my)\n", 112 | "\n", 113 | "print(type(my))" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "three\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "print(my[2])" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 8, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "()\n", 143 | "\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "t = ()\n", 149 | "\n", 150 | "print(t)\n", 151 | "\n", 152 | "print(type(t))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 11, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "10\n", 165 | "\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "t = (10)\n", 171 | "\n", 172 | "print(t)\n", 173 | "\n", 174 | "print(type(t))" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 12, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "(10,)\n", 187 | "\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "t = (10,)\n", 193 | "\n", 194 | "print(t)\n", 195 | "\n", 196 | "print(type(t))" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "# Tuple Unpacking" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 1, 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "1\n", 216 | "2\n", 217 | "3\n" 218 | ] 219 | } 220 | ], 221 | "source": [ 222 | "n = (1,2,3)\n", 223 | "\n", 224 | "a,b,c = n\n", 225 | "\n", 226 | "print(a)\n", 227 | "print(b)\n", 228 | "print(c)" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 2, 234 | "metadata": {}, 235 | "outputs": [ 236 | { 237 | "ename": "ValueError", 238 | "evalue": "not enough values to unpack (expected 4, got 3)", 239 | "output_type": "error", 240 | "traceback": [ 241 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 242 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 243 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0md\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 244 | "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 4, got 3)" 245 | ] 246 | } 247 | ], 248 | "source": [ 249 | "n = (1,2,3)\n", 250 | "\n", 251 | "a,b,c,d = n\n", 252 | "\n", 253 | "print(a)\n", 254 | "print(b)\n", 255 | "print(c)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 3, 261 | "metadata": {}, 262 | "outputs": [ 263 | { 264 | "ename": "ValueError", 265 | "evalue": "too many values to unpack (expected 3)", 266 | "output_type": "error", 267 | "traceback": [ 268 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 269 | "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", 270 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mn\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 271 | "\u001b[0;31mValueError\u001b[0m: too many values to unpack (expected 3)" 272 | ] 273 | } 274 | ], 275 | "source": [ 276 | "n = (1,2,3,4)\n", 277 | "\n", 278 | "a,b,c = n\n", 279 | "\n", 280 | "print(a)\n", 281 | "print(b)\n", 282 | "print(c)" 283 | ] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "metadata": {}, 288 | "source": [ 289 | "## Swap two numbers" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": null, 295 | "metadata": {}, 296 | "outputs": [], 297 | "source": [] 298 | } 299 | ], 300 | "metadata": { 301 | "kernelspec": { 302 | "display_name": "Python 3", 303 | "language": "python", 304 | "name": "python3" 305 | }, 306 | "language_info": { 307 | "codemirror_mode": { 308 | "name": "ipython", 309 | "version": 3 310 | }, 311 | "file_extension": ".py", 312 | "mimetype": "text/x-python", 313 | "name": "python", 314 | "nbconvert_exporter": "python", 315 | "pygments_lexer": "ipython3", 316 | "version": "3.7.6" 317 | } 318 | }, 319 | "nbformat": 4, 320 | "nbformat_minor": 4 321 | } 322 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/23_Object Oriented Programming-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object-Oriented Programming\n", 8 | "Classes\n", 9 | "\n", 10 | "Objects\n", 11 | "\n", 12 | "Method Calls\n", 13 | "\n", 14 | "Inheritance and Its Types\n", 15 | "\n", 16 | "Overloading\n", 17 | "\n", 18 | "Overriding\n", 19 | "\n", 20 | "Data Hiding\n", 21 | "\n", 22 | "Operator Overloading" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# OOPs\n", 30 | "\n", 31 | "7 Properties of OOPs\n", 32 | "\n", 33 | "1. Class\n", 34 | " \n", 35 | " Updated version of structure (struct C programming).\n", 36 | " Collection of variables and methods.\n", 37 | " Class is a blueprint.\n", 38 | "2. Object\n", 39 | " Run time or real time entity.\n", 40 | " hash code - id()\n", 41 | " \n", 42 | "3. Inheritance\n", 43 | " " 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "int a = 10; # 2 bytes\n", 53 | "\n", 54 | "struct abc{\n", 55 | " int a;\n", 56 | " float b;\n", 57 | " char c;\n", 58 | "}" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 1, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "10\n", 71 | "94405754090528\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "a = 10\n", 77 | "\n", 78 | "print(a)\n", 79 | "\n", 80 | "print(id(a))" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [] 89 | } 90 | ], 91 | "metadata": { 92 | "kernelspec": { 93 | "display_name": "Python 3", 94 | "language": "python", 95 | "name": "python3" 96 | }, 97 | "language_info": { 98 | "codemirror_mode": { 99 | "name": "ipython", 100 | "version": 3 101 | }, 102 | "file_extension": ".py", 103 | "mimetype": "text/x-python", 104 | "name": "python", 105 | "nbconvert_exporter": "python", 106 | "pygments_lexer": "ipython3", 107 | "version": "3.7.6" 108 | } 109 | }, 110 | "nbformat": 4, 111 | "nbformat_minor": 4 112 | } 113 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/24_Object Oriented Programming-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object-Oriented Programming\n", 8 | "Classes\n", 9 | "\n", 10 | "Objects\n", 11 | "\n", 12 | "Method Calls\n", 13 | "\n", 14 | "Inheritance and Its Types\n", 15 | "\n", 16 | "Overloading\n", 17 | "\n", 18 | "Overriding\n", 19 | "\n", 20 | "Data Hiding\n", 21 | "\n", 22 | "Operator Overloading" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# OOPs\n", 30 | "\n", 31 | "7 Properties of OOPs\n", 32 | "\n", 33 | "1. Class\n", 34 | " \n", 35 | " Updated version of structure (struct C programming).\n", 36 | " Collection of variables and methods.\n", 37 | " Class is a blueprint.\n", 38 | "2. Object\n", 39 | " Run time or real time entity.\n", 40 | " hash code - id()\n", 41 | " \n", 42 | "3. Abstraction and Encapsulation\n", 43 | " Abstraction - Showing only essential features without showing any backgroud details.\n", 44 | " Encapsulation - Wrapping up of data in a single unit.\n", 45 | " \n", 46 | "4. Inheritance\n", 47 | " Acquiring properties of one class into another.\n", 48 | " Code reuse\n", 49 | " Types - \n", 50 | " - single level\n", 51 | " - multilevel \n", 52 | " - hierarchical \n", 53 | " - multiple\n", 54 | " - hybrid\n", 55 | "5. Polymorphism\n", 56 | " Same name multiple functionalities\n", 57 | " - Method overloading\n", 58 | " - method overriding\n", 59 | " add()\n", 60 | " add(x, y)\n", 61 | " add(a,b,c)\n", 62 | " add()\n", 63 | "6. Dynamic Memory Allocation\n", 64 | " run time memory allocation / late binding / dynamic binding\n", 65 | "7. Message Passing\n", 66 | " communication between objects." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "int a = 10; # 2 bytes\n", 76 | "\n", 77 | "struct abc{\n", 78 | " int a;\n", 79 | " float b;\n", 80 | " char c;\n", 81 | "}" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "10\n", 94 | "94405754090528\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "a = 10\n", 100 | "\n", 101 | "print(a)\n", 102 | "\n", 103 | "print(id(a))" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "windows xp\n", 113 | "\n", 114 | "windows 7\n", 115 | "^\n", 116 | "|\n", 117 | "windows 10" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 5, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "class Cricket:\n", 127 | " \n", 128 | " def bat(self):\n", 129 | " print(\"Batting\")\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 6, 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "name": "stdout", 139 | "output_type": "stream", 140 | "text": [ 141 | "Batting\n" 142 | ] 143 | } 144 | ], 145 | "source": [ 146 | "c = Cricket()\n", 147 | "\n", 148 | "c.bat()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 7, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "<__main__.Cricket object at 0x7f64641321d0>\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "print(c)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 8, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "140069152432592\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "print(id(c))" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 9, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "<__main__.Cricket object at 0x7f6464132f90>\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "print(Cricket())" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 10, 205 | "metadata": {}, 206 | "outputs": [ 207 | { 208 | "name": "stdout", 209 | "output_type": "stream", 210 | "text": [ 211 | "Baller\n", 212 | "<__main__.Baller object at 0x7f646412d290>\n", 213 | "<__main__.Baller object at 0x7f646412d290>\n" 214 | ] 215 | } 216 | ], 217 | "source": [ 218 | "class Baller:\n", 219 | " \n", 220 | " def bat(self): # self = c\n", 221 | " print(\"Baller\")\n", 222 | " print(self)\n", 223 | "\n", 224 | "c = Baller()\n", 225 | "\n", 226 | "c.bat()\n", 227 | "print(c)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "TV Blueprint - class\n", 237 | "- smart tv\n", 238 | "- colors\n", 239 | "- usb\n", 240 | "- hdmi\n", 241 | "- wifi\n", 242 | "\n", 243 | "Actual TV - object\n", 244 | "\n", 245 | "remote - reference" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": null, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": null, 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": null, 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [] 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.7.6" 294 | } 295 | }, 296 | "nbformat": 4, 297 | "nbformat_minor": 4 298 | } 299 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/28_Python File Handling-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/29_30_Exception Handling-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Exception Handling\n", 8 | "Common Exceptions\n", 9 | "\n", 10 | "Exception Handling\n", 11 | "\n", 12 | "Try\n", 13 | "\n", 14 | "Except\n", 15 | "\n", 16 | "Try except else\n", 17 | "\n", 18 | "Finally\n", 19 | "\n", 20 | "Raising exceptions\n", 21 | "\n", 22 | "Assertion" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# Exception\n", 30 | "\n", 31 | "runtime errors" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "ename": "ZeroDivisionError", 41 | "evalue": "division by zero", 42 | "output_type": "error", 43 | "traceback": [ 44 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 45 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 46 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 47 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "a = 0\n", 53 | "b = 1\n", 54 | "\n", 55 | "print(b/a)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "ename": "TypeError", 65 | "evalue": "can only concatenate str (not \"int\") to str", 66 | "output_type": "error", 67 | "traceback": [ 68 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 69 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 70 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"A\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 71 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "print(\"A\" + 10)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "ename": "NameError", 86 | "evalue": "name 'y' is not defined", 87 | "output_type": "error", 88 | "traceback": [ 89 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 90 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 91 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 92 | "\u001b[0;31mNameError\u001b[0m: name 'y' is not defined" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "print(y)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### common exceptions\n", 105 | "\n", 106 | "ImportError\n", 107 | "\n", 108 | "IndexError\n", 109 | "\n", 110 | "NameError\n", 111 | "\n", 112 | "SyntaxError\n", 113 | "\n", 114 | "TypeError\n", 115 | "\n", 116 | "ValueError" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "# Exception Handling\n", 124 | "\n", 125 | "try - a block that might contains exceptions\n", 126 | "\n", 127 | "except - contains the exception msg / handling code" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 4, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "An Error Occured\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "try:\n", 145 | " a = 7\n", 146 | " b = 0\n", 147 | " print(a/b)\n", 148 | " print(\"Finish\")\n", 149 | "except ZeroDivisionError:\n", 150 | " print(\"An Error Occured\")" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 6, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "Help on class ZeroDivisionError in module builtins:\n", 163 | "\n", 164 | "class ZeroDivisionError(ArithmeticError)\n", 165 | " | Second argument to a division or modulo operation was zero.\n", 166 | " | \n", 167 | " | Method resolution order:\n", 168 | " | ZeroDivisionError\n", 169 | " | ArithmeticError\n", 170 | " | Exception\n", 171 | " | BaseException\n", 172 | " | object\n", 173 | " | \n", 174 | " | Methods defined here:\n", 175 | " | \n", 176 | " | __init__(self, /, *args, **kwargs)\n", 177 | " | Initialize self. See help(type(self)) for accurate signature.\n", 178 | " | \n", 179 | " | ----------------------------------------------------------------------\n", 180 | " | Static methods defined here:\n", 181 | " | \n", 182 | " | __new__(*args, **kwargs) from builtins.type\n", 183 | " | Create and return a new object. See help(type) for accurate signature.\n", 184 | " | \n", 185 | " | ----------------------------------------------------------------------\n", 186 | " | Methods inherited from BaseException:\n", 187 | " | \n", 188 | " | __delattr__(self, name, /)\n", 189 | " | Implement delattr(self, name).\n", 190 | " | \n", 191 | " | __getattribute__(self, name, /)\n", 192 | " | Return getattr(self, name).\n", 193 | " | \n", 194 | " | __reduce__(...)\n", 195 | " | Helper for pickle.\n", 196 | " | \n", 197 | " | __repr__(self, /)\n", 198 | " | Return repr(self).\n", 199 | " | \n", 200 | " | __setattr__(self, name, value, /)\n", 201 | " | Implement setattr(self, name, value).\n", 202 | " | \n", 203 | " | __setstate__(...)\n", 204 | " | \n", 205 | " | __str__(self, /)\n", 206 | " | Return str(self).\n", 207 | " | \n", 208 | " | with_traceback(...)\n", 209 | " | Exception.with_traceback(tb) --\n", 210 | " | set self.__traceback__ to tb and return self.\n", 211 | " | \n", 212 | " | ----------------------------------------------------------------------\n", 213 | " | Data descriptors inherited from BaseException:\n", 214 | " | \n", 215 | " | __cause__\n", 216 | " | exception cause\n", 217 | " | \n", 218 | " | __context__\n", 219 | " | exception context\n", 220 | " | \n", 221 | " | __dict__\n", 222 | " | \n", 223 | " | __suppress_context__\n", 224 | " | \n", 225 | " | __traceback__\n", 226 | " | \n", 227 | " | args\n", 228 | "\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "help(ZeroDivisionError)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 7, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "Error Occured\n" 246 | ] 247 | } 248 | ], 249 | "source": [ 250 | "try:\n", 251 | " a = 10\n", 252 | " print(\"Hi\" + a)\n", 253 | " print(a/2)\n", 254 | "except ZeroDivisionError:\n", 255 | " print(\"Do not Divide by Zero\")\n", 256 | "except (ValueError, TypeError):\n", 257 | " print(\"Error Occured\")" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 8, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "Something went wrong!\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "try:\n", 275 | " w = \"String\"\n", 276 | " print(w/0)\n", 277 | "except:\n", 278 | " print(\"Something went wrong!\")" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [] 287 | } 288 | ], 289 | "metadata": { 290 | "kernelspec": { 291 | "display_name": "Python 3", 292 | "language": "python", 293 | "name": "python3" 294 | }, 295 | "language_info": { 296 | "codemirror_mode": { 297 | "name": "ipython", 298 | "version": 3 299 | }, 300 | "file_extension": ".py", 301 | "mimetype": "text/x-python", 302 | "name": "python", 303 | "nbconvert_exporter": "python", 304 | "pygments_lexer": "ipython3", 305 | "version": "3.7.6" 306 | } 307 | }, 308 | "nbformat": 4, 309 | "nbformat_minor": 4 310 | } 311 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/29_Python File Handling-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# File Handling\n", 8 | "\n", 9 | "1. Read\n", 10 | "2. Write\n", 11 | "3. Append" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "## Read a file" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "<_io.TextIOWrapper name='student.txt' mode='r' encoding='UTF-8'>\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "f = open(\"student.txt\")\n", 36 | "\n", 37 | "print(f)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "this is a city file.\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "f = open(\"student.txt\", 'r')\n", 55 | "\n", 56 | "print(f.read())" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "print(type(f))" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 4, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "print(type(f.read()))" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "f.close()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "### number of characters" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "Help on built-in function read:\n", 119 | "\n", 120 | "read(size=-1, /) method of _io.TextIOWrapper instance\n", 121 | " Read at most n characters from stream.\n", 122 | " \n", 123 | " Read from underlying buffer until we have n characters or we hit EOF.\n", 124 | " If n is negative or omitted, read until EOF.\n", 125 | "\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "help(f.read)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 7, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "this \n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "f = open(\"student.txt\", 'r')\n", 148 | "\n", 149 | "print(f.read(5))" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 8, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stdout", 159 | "output_type": "stream", 160 | "text": [ 161 | "this is a city file.\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "f = open(\"student.txt\", 'r')\n", 167 | "\n", 168 | "print(f.readline())" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 10, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "['this is a city file.\\n', 'I m from India.']\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "f = open(\"student.txt\", 'r')\n", 186 | "\n", 187 | "print(f.readlines())" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 11, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "I m from India.\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "f = open(\"student.txt\", 'r')\n", 205 | "\n", 206 | "print(f.readlines()[1])" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "### using a loop" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 1, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "this is a city file.\n", 226 | "\n", 227 | "I m from India.\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "f = open(\"student.txt\", 'r')\n", 233 | "\n", 234 | "for i in f:\n", 235 | " print(i)\n", 236 | "\n", 237 | "f.close()" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 2, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "name": "stdout", 247 | "output_type": "stream", 248 | "text": [ 249 | "2\n" 250 | ] 251 | } 252 | ], 253 | "source": [ 254 | "print(len(open(\"student.txt\", 'r').readlines()))" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 4, 260 | "metadata": {}, 261 | "outputs": [ 262 | { 263 | "ename": "FileNotFoundError", 264 | "evalue": "[Errno 2] No such file or directory: 'hello.txt'", 265 | "output_type": "error", 266 | "traceback": [ 267 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 268 | "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", 269 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello.txt\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 270 | "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'hello.txt'" 271 | ] 272 | } 273 | ], 274 | "source": [ 275 | "print(len(open(\"hello.txt\", 'r')))" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 3, 281 | "metadata": { 282 | "scrolled": true 283 | }, 284 | "outputs": [ 285 | { 286 | "ename": "TypeError", 287 | "evalue": "object of type '_io.TextIOWrapper' has no len()", 288 | "output_type": "error", 289 | "traceback": [ 290 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 291 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 292 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"student.txt\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 293 | "\u001b[0;31mTypeError\u001b[0m: object of type '_io.TextIOWrapper' has no len()" 294 | ] 295 | } 296 | ], 297 | "source": [ 298 | "print(len(open(\"student.txt\", 'r')))" 299 | ] 300 | }, 301 | { 302 | "cell_type": "markdown", 303 | "metadata": {}, 304 | "source": [ 305 | "### write a file" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 5, 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "f = open(\"mumbai.txt\", 'w')\n", 315 | "\n", 316 | "f.write('This is a virus.')\n", 317 | "\n", 318 | "f.close()" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 6, 324 | "metadata": {}, 325 | "outputs": [], 326 | "source": [ 327 | "f = open(\"student.txt\", 'w')\n", 328 | "\n", 329 | "f.close()" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 7, 335 | "metadata": {}, 336 | "outputs": [ 337 | { 338 | "name": "stdout", 339 | "output_type": "stream", 340 | "text": [ 341 | "This is a virus.\n" 342 | ] 343 | } 344 | ], 345 | "source": [ 346 | "f = open(\"mumbai.txt\", 'r')\n", 347 | "\n", 348 | "print(f.read())\n", 349 | "\n", 350 | "f.close()" 351 | ] 352 | }, 353 | { 354 | "cell_type": "code", 355 | "execution_count": 8, 356 | "metadata": {}, 357 | "outputs": [ 358 | { 359 | "name": "stdout", 360 | "output_type": "stream", 361 | "text": [ 362 | "spiderman is the new ironman\n" 363 | ] 364 | } 365 | ], 366 | "source": [ 367 | "s = \"spiderman is the new ironman\"\n", 368 | "\n", 369 | "f = open(\"queens.txt\", 'w')\n", 370 | "\n", 371 | "f.write(s)\n", 372 | "\n", 373 | "f.close()\n", 374 | "\n", 375 | "f = open(\"queens.txt\", 'r')\n", 376 | "print(f.read())\n", 377 | "\n", 378 | "f.close()" 379 | ] 380 | }, 381 | { 382 | "cell_type": "markdown", 383 | "metadata": {}, 384 | "source": [ 385 | "### append a file\n", 386 | "\n", 387 | "edit a file" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": 9, 393 | "metadata": {}, 394 | "outputs": [], 395 | "source": [ 396 | "f = open(\"queens.txt\", 'a')\n", 397 | "\n", 398 | "f.write('\\nThis is a virus.')\n", 399 | "\n", 400 | "f.close()" 401 | ] 402 | }, 403 | { 404 | "cell_type": "markdown", 405 | "metadata": {}, 406 | "source": [ 407 | "## with statement" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 10, 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "spiderman is the new ironman\n", 420 | "This is a virus.\n" 421 | ] 422 | } 423 | ], 424 | "source": [ 425 | "with open(\"queens.txt\",'r') as p:\n", 426 | " print(p.read())" 427 | ] 428 | }, 429 | { 430 | "cell_type": "markdown", 431 | "metadata": {}, 432 | "source": [ 433 | "**WAP to open a file and find the largest word in it**" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "metadata": {}, 439 | "source": [ 440 | "**WAP to check a file is closed or not.**" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 16, 446 | "metadata": {}, 447 | "outputs": [], 448 | "source": [ 449 | "f = open(\"student.txt\", 'r')\n", 450 | "f.close()" 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 17, 456 | "metadata": {}, 457 | "outputs": [ 458 | { 459 | "name": "stdout", 460 | "output_type": "stream", 461 | "text": [ 462 | "Hi\n" 463 | ] 464 | } 465 | ], 466 | "source": [ 467 | "if f.closed:\n", 468 | " print(\"Hi\")" 469 | ] 470 | }, 471 | { 472 | "cell_type": "code", 473 | "execution_count": null, 474 | "metadata": {}, 475 | "outputs": [], 476 | "source": [] 477 | }, 478 | { 479 | "cell_type": "code", 480 | "execution_count": null, 481 | "metadata": {}, 482 | "outputs": [], 483 | "source": [] 484 | } 485 | ], 486 | "metadata": { 487 | "kernelspec": { 488 | "display_name": "Python 3", 489 | "language": "python", 490 | "name": "python3" 491 | }, 492 | "language_info": { 493 | "codemirror_mode": { 494 | "name": "ipython", 495 | "version": 3 496 | }, 497 | "file_extension": ".py", 498 | "mimetype": "text/x-python", 499 | "name": "python", 500 | "nbconvert_exporter": "python", 501 | "pygments_lexer": "ipython3", 502 | "version": "3.7.6" 503 | } 504 | }, 505 | "nbformat": 4, 506 | "nbformat_minor": 4 507 | } 508 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/31_Exception Handling-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Exception Handling\n", 8 | "Common Exceptions\n", 9 | "\n", 10 | "Exception Handling\n", 11 | "\n", 12 | "Try\n", 13 | "\n", 14 | "Except\n", 15 | "\n", 16 | "Try except else\n", 17 | "\n", 18 | "Finally\n", 19 | "\n", 20 | "Raising exceptions\n", 21 | "\n", 22 | "Assertion" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# Exception\n", 30 | "\n", 31 | "runtime errors" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "ename": "ZeroDivisionError", 41 | "evalue": "division by zero", 42 | "output_type": "error", 43 | "traceback": [ 44 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 45 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 46 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 47 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "a = 0\n", 53 | "b = 1\n", 54 | "\n", 55 | "print(b/a)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "ename": "TypeError", 65 | "evalue": "can only concatenate str (not \"int\") to str", 66 | "output_type": "error", 67 | "traceback": [ 68 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 69 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 70 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"A\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 71 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "print(\"A\" + 10)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "ename": "NameError", 86 | "evalue": "name 'y' is not defined", 87 | "output_type": "error", 88 | "traceback": [ 89 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 90 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 91 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 92 | "\u001b[0;31mNameError\u001b[0m: name 'y' is not defined" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "print(y)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### common exceptions\n", 105 | "\n", 106 | "ImportError\n", 107 | "\n", 108 | "IndexError\n", 109 | "\n", 110 | "NameError\n", 111 | "\n", 112 | "SyntaxError\n", 113 | "\n", 114 | "TypeError\n", 115 | "\n", 116 | "ValueError" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "# Exception Handling\n", 124 | "\n", 125 | "try - a block that might contains exceptions\n", 126 | "\n", 127 | "except - contains the exception msg / handling code" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 4, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "An Error Occured\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "try:\n", 145 | " a = 7\n", 146 | " b = 0\n", 147 | " print(a/b)\n", 148 | " print(\"Finish\")\n", 149 | "except ZeroDivisionError:\n", 150 | " print(\"An Error Occured\")" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 6, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "Help on class ZeroDivisionError in module builtins:\n", 163 | "\n", 164 | "class ZeroDivisionError(ArithmeticError)\n", 165 | " | Second argument to a division or modulo operation was zero.\n", 166 | " | \n", 167 | " | Method resolution order:\n", 168 | " | ZeroDivisionError\n", 169 | " | ArithmeticError\n", 170 | " | Exception\n", 171 | " | BaseException\n", 172 | " | object\n", 173 | " | \n", 174 | " | Methods defined here:\n", 175 | " | \n", 176 | " | __init__(self, /, *args, **kwargs)\n", 177 | " | Initialize self. See help(type(self)) for accurate signature.\n", 178 | " | \n", 179 | " | ----------------------------------------------------------------------\n", 180 | " | Static methods defined here:\n", 181 | " | \n", 182 | " | __new__(*args, **kwargs) from builtins.type\n", 183 | " | Create and return a new object. See help(type) for accurate signature.\n", 184 | " | \n", 185 | " | ----------------------------------------------------------------------\n", 186 | " | Methods inherited from BaseException:\n", 187 | " | \n", 188 | " | __delattr__(self, name, /)\n", 189 | " | Implement delattr(self, name).\n", 190 | " | \n", 191 | " | __getattribute__(self, name, /)\n", 192 | " | Return getattr(self, name).\n", 193 | " | \n", 194 | " | __reduce__(...)\n", 195 | " | Helper for pickle.\n", 196 | " | \n", 197 | " | __repr__(self, /)\n", 198 | " | Return repr(self).\n", 199 | " | \n", 200 | " | __setattr__(self, name, value, /)\n", 201 | " | Implement setattr(self, name, value).\n", 202 | " | \n", 203 | " | __setstate__(...)\n", 204 | " | \n", 205 | " | __str__(self, /)\n", 206 | " | Return str(self).\n", 207 | " | \n", 208 | " | with_traceback(...)\n", 209 | " | Exception.with_traceback(tb) --\n", 210 | " | set self.__traceback__ to tb and return self.\n", 211 | " | \n", 212 | " | ----------------------------------------------------------------------\n", 213 | " | Data descriptors inherited from BaseException:\n", 214 | " | \n", 215 | " | __cause__\n", 216 | " | exception cause\n", 217 | " | \n", 218 | " | __context__\n", 219 | " | exception context\n", 220 | " | \n", 221 | " | __dict__\n", 222 | " | \n", 223 | " | __suppress_context__\n", 224 | " | \n", 225 | " | __traceback__\n", 226 | " | \n", 227 | " | args\n", 228 | "\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "help(ZeroDivisionError)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 7, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "Error Occured\n" 246 | ] 247 | } 248 | ], 249 | "source": [ 250 | "try:\n", 251 | " a = 10\n", 252 | " print(\"Hi\" + a)\n", 253 | " print(a/2)\n", 254 | "except ZeroDivisionError:\n", 255 | " print(\"Do not Divide by Zero\")\n", 256 | "except (ValueError, TypeError):\n", 257 | " print(\"Error Occured\")" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 8, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "Something went wrong!\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "try:\n", 275 | " w = \"String\"\n", 276 | " print(w/0)\n", 277 | "except:\n", 278 | " print(\"Something went wrong!\")" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": {}, 284 | "source": [ 285 | "## else" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": null, 291 | "metadata": {}, 292 | "outputs": [], 293 | "source": [ 294 | "try:\n", 295 | " print(1)\n", 296 | "except ZeroDivisionError:\n", 297 | " print(2)\n", 298 | "except:\n", 299 | " print(3)" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": null, 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": null, 312 | "metadata": {}, 313 | "outputs": [], 314 | "source": [] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": null, 319 | "metadata": {}, 320 | "outputs": [], 321 | "source": [] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": null, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [] 329 | }, 330 | { 331 | "cell_type": "code", 332 | "execution_count": null, 333 | "metadata": {}, 334 | "outputs": [], 335 | "source": [] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": null, 340 | "metadata": {}, 341 | "outputs": [], 342 | "source": [] 343 | } 344 | ], 345 | "metadata": { 346 | "kernelspec": { 347 | "display_name": "Python 3", 348 | "language": "python", 349 | "name": "python3" 350 | }, 351 | "language_info": { 352 | "codemirror_mode": { 353 | "name": "ipython", 354 | "version": 3 355 | }, 356 | "file_extension": ".py", 357 | "mimetype": "text/x-python", 358 | "name": "python", 359 | "nbconvert_exporter": "python", 360 | "pygments_lexer": "ipython3", 361 | "version": "3.7.6" 362 | } 363 | }, 364 | "nbformat": 4, 365 | "nbformat_minor": 4 366 | } 367 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/35_Python Stack-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Data Structures\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "c\n", 18 | "\n", 19 | "int a = 10;\n", 20 | "# 2 bytes" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "struct cars{\n", 30 | " int customer_id;\n", 31 | " float price;\n", 32 | " char name[10];\n", 33 | "}" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "struct cars c1; # 16 bytes\n", 43 | " int a;" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "c++\n", 53 | "\n", 54 | "class" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "https://github.com/hemansnation/Data-Structures-and-Algorithms" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "# Stack\n", 69 | "\n", 70 | "LIFO (Last In First Out)\n", 71 | "\n", 72 | "### Stack using Python List\n", 73 | "\n", 74 | "push\n", 75 | "\n", 76 | "pop\n", 77 | "\n", 78 | "display" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "\n", 88 | "30\n", 89 | "20\n", 90 | "10" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 1, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "[10, 20, 30]\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "stack = []\n", 108 | "\n", 109 | "stack.append(10)\n", 110 | "stack.append(20)\n", 111 | "stack.append(30)\n", 112 | "\n", 113 | "print(stack)\n", 114 | "\n" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 2, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "stack.append(50)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 3, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "[10, 20, 30, 50]" 135 | ] 136 | }, 137 | "execution_count": 3, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "stack" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 4, 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "50\n" 156 | ] 157 | } 158 | ], 159 | "source": [ 160 | "print(stack.pop())" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 5, 166 | "metadata": {}, 167 | "outputs": [ 168 | { 169 | "data": { 170 | "text/plain": [ 171 | "[10, 20, 30]" 172 | ] 173 | }, 174 | "execution_count": 5, 175 | "metadata": {}, 176 | "output_type": "execute_result" 177 | } 178 | ], 179 | "source": [ 180 | "stack" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 6, 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "30\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "top = stack[-1]\n", 198 | "\n", 199 | "print(top)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "# Stack using Class from scratch" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 18, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "class Stack:\n", 216 | " \n", 217 | " def __init__(self):\n", 218 | " self.data = []\n", 219 | " self.size = 0\n", 220 | " \n", 221 | " def __len__(self):\n", 222 | " return self.size\n", 223 | " \n", 224 | " def is_empty(self):\n", 225 | " return self.size == 0\n", 226 | " \n", 227 | " def push(self, value):\n", 228 | " self.data.append(value)\n", 229 | " self.size += 1\n", 230 | " \n", 231 | " def top(self):\n", 232 | " if self.is_empty():\n", 233 | " return \"Stack is Underflow\"\n", 234 | " return self.data[-1]\n", 235 | " \n", 236 | " def pop(self):\n", 237 | " if self.is_empty():\n", 238 | " return \"Stack is Empty\"\n", 239 | " return self.data.pop()\n", 240 | " \n", 241 | " def display(self):\n", 242 | " return self.data" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 19, 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [ 251 | "stack = Stack()" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 20, 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "data": { 261 | "text/plain": [ 262 | "__main__.Stack" 263 | ] 264 | }, 265 | "execution_count": 20, 266 | "metadata": {}, 267 | "output_type": "execute_result" 268 | } 269 | ], 270 | "source": [ 271 | "type(stack)" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 21, 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "data": { 281 | "text/plain": [ 282 | "'Stack is Underflow'" 283 | ] 284 | }, 285 | "execution_count": 21, 286 | "metadata": {}, 287 | "output_type": "execute_result" 288 | } 289 | ], 290 | "source": [ 291 | "stack.top()" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 22, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "data": { 301 | "text/plain": [ 302 | "True" 303 | ] 304 | }, 305 | "execution_count": 22, 306 | "metadata": {}, 307 | "output_type": "execute_result" 308 | } 309 | ], 310 | "source": [ 311 | "stack.is_empty()" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 23, 317 | "metadata": {}, 318 | "outputs": [], 319 | "source": [ 320 | "stack.push(10)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 24, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "stack.push(11)" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 25, 335 | "metadata": {}, 336 | "outputs": [], 337 | "source": [ 338 | "stack.push(81)\n", 339 | "stack.push(100)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 26, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "[10, 11, 81, 100]" 351 | ] 352 | }, 353 | "execution_count": 26, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "stack.display()" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 27, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "100" 371 | ] 372 | }, 373 | "execution_count": 27, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "stack.top()" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 28, 385 | "metadata": {}, 386 | "outputs": [ 387 | { 388 | "data": { 389 | "text/plain": [ 390 | "4" 391 | ] 392 | }, 393 | "execution_count": 28, 394 | "metadata": {}, 395 | "output_type": "execute_result" 396 | } 397 | ], 398 | "source": [ 399 | "stack.__len__()" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": null, 405 | "metadata": {}, 406 | "outputs": [], 407 | "source": [] 408 | } 409 | ], 410 | "metadata": { 411 | "kernelspec": { 412 | "display_name": "Python 3", 413 | "language": "python", 414 | "name": "python3" 415 | }, 416 | "language_info": { 417 | "codemirror_mode": { 418 | "name": "ipython", 419 | "version": 3 420 | }, 421 | "file_extension": ".py", 422 | "mimetype": "text/x-python", 423 | "name": "python", 424 | "nbconvert_exporter": "python", 425 | "pygments_lexer": "ipython3", 426 | "version": "3.7.6" 427 | } 428 | }, 429 | "nbformat": 4, 430 | "nbformat_minor": 4 431 | } 432 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/36_Queue and Linear Searching-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Queue\n", 8 | "\n", 9 | "FIFO (First In First Out)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | " None 50 100 70\n", 19 | " rare\n", 20 | " front" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "insert - enqueue\n", 30 | "delete - dequeue\n", 31 | "display\n", 32 | "first" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "[5]" 44 | ] 45 | }, 46 | "execution_count": 3, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "l = [None]\n", 53 | "\n", 54 | "l[0] = 5\n", 55 | "\n", 56 | "l" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "[None, None, None]" 68 | ] 69 | }, 70 | "execution_count": 4, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "[None] * 3" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 20, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "class Queue:\n", 86 | " \n", 87 | " DEFAULT_CAPACITY = 10\n", 88 | " \n", 89 | " def __init__(self):\n", 90 | " self.data = [None] * Queue.DEFAULT_CAPACITY # [None, None, None -----]\n", 91 | " self.size = 0\n", 92 | " self.front = 0\n", 93 | " self.rare = 0\n", 94 | " \n", 95 | " def __len__(self):\n", 96 | " return self.size\n", 97 | " \n", 98 | " def is_empty(self):\n", 99 | " return self.size == 0\n", 100 | " \n", 101 | " def first(self):\n", 102 | " if self.is_empty():\n", 103 | " return \"Queue is Empty\"\n", 104 | " return self.data[self.front]\n", 105 | " \n", 106 | " # dequeue - delete an element\n", 107 | " def dequeue(self):\n", 108 | " if self.is_empty():\n", 109 | " return \"Queue is Empty\"\n", 110 | " answer = self.data[self.rare]\n", 111 | " self.data[self.rare] = None\n", 112 | " \n", 113 | " self.rare += 1\n", 114 | " self.size -= 1\n", 115 | " \n", 116 | " return answer \n", 117 | " \n", 118 | " # enqueue - insert an element\n", 119 | " def enqueue(self, element):\n", 120 | " if self.size == Queue.DEFAULT_CAPACITY:\n", 121 | " return \"Queue is Overflow\"\n", 122 | " \n", 123 | " a = self.front + 1\n", 124 | " self.data[a] = element\n", 125 | " \n", 126 | " self.front += 1\n", 127 | " self.size += 1\n", 128 | " \n", 129 | " def display(self):\n", 130 | " if self.is_empty():\n", 131 | " return \"Queue is Empty\"\n", 132 | " i = self.rare\n", 133 | " while(i <= self.front):\n", 134 | " print(self.data[i])\n", 135 | " i += 1\n", 136 | " " 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 21, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "q = Queue()" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 22, 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "0" 157 | ] 158 | }, 159 | "execution_count": 22, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "q.__len__()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 23, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "True" 177 | ] 178 | }, 179 | "execution_count": 23, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "q.is_empty()" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 24, 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "q.enqueue(10)\n" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 25, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "10" 206 | ] 207 | }, 208 | "execution_count": 25, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "q.first()" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 26, 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "q.enqueue(50)\n", 224 | "q.enqueue(100)\n", 225 | "q.enqueue(15)\n" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 27, 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/plain": [ 236 | "15" 237 | ] 238 | }, 239 | "execution_count": 27, 240 | "metadata": {}, 241 | "output_type": "execute_result" 242 | } 243 | ], 244 | "source": [ 245 | "q.first()" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 28, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "4" 257 | ] 258 | }, 259 | "execution_count": 28, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "q.__len__()" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 29, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/plain": [ 276 | "0" 277 | ] 278 | }, 279 | "execution_count": 29, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "q.rare" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 31, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "None\n", 298 | "10\n", 299 | "50\n", 300 | "100\n", 301 | "15\n" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "q.display()" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "metadata": {}, 312 | "source": [ 313 | "# Searching" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 32, 319 | "metadata": {}, 320 | "outputs": [ 321 | { 322 | "name": "stdout", 323 | "output_type": "stream", 324 | "text": [ 325 | "True\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "a = [1,2,3,4,5,6,7,8,9,10]\n", 331 | "\n", 332 | "# membership operator\n", 333 | "\n", 334 | "print(2 in a)" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 33, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "False\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "print(20 in a)" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 34, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "name": "stdout", 361 | "output_type": "stream", 362 | "text": [ 363 | "True\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "print(20 not in a)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "metadata": {}, 374 | "source": [ 375 | "# Linear Search" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 36, 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "name": "stdout", 385 | "output_type": "stream", 386 | "text": [ 387 | "Enter a number100\n", 388 | "Search Fail\n" 389 | ] 390 | } 391 | ], 392 | "source": [ 393 | "l = [11,25,3,41,50,88, 66, 99]\n", 394 | "# n\n", 395 | "\n", 396 | "# n = 88\n", 397 | "n = int(input(\"Enter a number\"))\n", 398 | "\n", 399 | "## flag bit variable\n", 400 | "f = 0\n", 401 | "\n", 402 | "for i in range(len(l)):\n", 403 | " if l[i] == n:\n", 404 | " f = 1\n", 405 | " break\n", 406 | "\n", 407 | "if f == 1:\n", 408 | " print(\"Search Success\")\n", 409 | "else:\n", 410 | " print(\"Search Fail\")" 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "execution_count": null, 416 | "metadata": {}, 417 | "outputs": [], 418 | "source": [] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "metadata": {}, 431 | "outputs": [], 432 | "source": [] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": null, 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": {}, 445 | "outputs": [], 446 | "source": [] 447 | } 448 | ], 449 | "metadata": { 450 | "kernelspec": { 451 | "display_name": "Python 3", 452 | "language": "python", 453 | "name": "python3" 454 | }, 455 | "language_info": { 456 | "codemirror_mode": { 457 | "name": "ipython", 458 | "version": 3 459 | }, 460 | "file_extension": ".py", 461 | "mimetype": "text/x-python", 462 | "name": "python", 463 | "nbconvert_exporter": "python", 464 | "pygments_lexer": "ipython3", 465 | "version": "3.7.6" 466 | } 467 | }, 468 | "nbformat": 4, 469 | "nbformat_minor": 4 470 | } 471 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/4_Conditional Statements-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Conditional Statements\n", 8 | "1. If Else\n", 9 | "2. If\n", 10 | "3. Else\n", 11 | "4. El If (else if)\n", 12 | "5. If Else Ternary Expression" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "Hello\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "a = 10\n", 30 | "\n", 31 | "if a > 5:\n", 32 | " print(\"Hello\")" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "a = 10\n", 42 | "\n", 43 | "if a > 15:\n", 44 | " print(\"Hello\")" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 3, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Hello\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "a = 10\n", 62 | "\n", 63 | "if a > 5:\n", 64 | " print(\"Hello\")\n", 65 | "else:\n", 66 | " print(\"Bye\")" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "Bye\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "a = 10\n", 84 | "\n", 85 | "if a > 15:\n", 86 | " print(\"Hello\")\n", 87 | "else:\n", 88 | " print(\"Bye\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 5, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "ename": "SyntaxError", 98 | "evalue": "invalid syntax (, line 1)", 99 | "output_type": "error", 100 | "traceback": [ 101 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m else:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "else:\n", 107 | " print(\"Hi\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 8, 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "Indore\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "a = 5\n", 125 | "\n", 126 | "if a == 10:\n", 127 | " print(\"Hello\")\n", 128 | " print(\"Hi\")\n", 129 | "elif a < 6:\n", 130 | " print(\"Indore\")\n", 131 | "elif a == 5:\n", 132 | " print(\"Goa\")\n", 133 | "else:\n", 134 | " print(\"Incorrect\")" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 9, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "Indore\n" 147 | ] 148 | } 149 | ], 150 | "source": [ 151 | "a = 5\n", 152 | "\n", 153 | "if a == 10:\n", 154 | " print(\"Hello\")\n", 155 | " print(\"Hi\")\n", 156 | "elif a < 6:\n", 157 | " print(\"Indore\")\n", 158 | "elif a == 5:\n", 159 | " print(\"Goa\")" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": 10, 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "ename": "SyntaxError", 169 | "evalue": "invalid syntax (, line 3)", 170 | "output_type": "error", 171 | "traceback": [ 172 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m elif a < 6:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 173 | ] 174 | } 175 | ], 176 | "source": [ 177 | "a = 5\n", 178 | "\n", 179 | "elif a < 6:\n", 180 | " print(\"Indore\")\n", 181 | "elif a == 5:\n", 182 | " print(\"Goa\")" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 13, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "1\n", 195 | "3\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "a = 5\n", 201 | "if a == 5:\n", 202 | " print(1)\n", 203 | "if a < 4:\n", 204 | " print(2)\n", 205 | "else:\n", 206 | " print(3)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "### Nested If else" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 14, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "1\n", 226 | "3\n", 227 | "4\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "a = 7\n", 233 | "\n", 234 | "if a > 4:\n", 235 | " print(1)\n", 236 | " if a == 5:\n", 237 | " print(2)\n", 238 | " else:\n", 239 | " print(3)\n", 240 | " if a == 7:\n", 241 | " print(4)\n", 242 | "else:\n", 243 | " print(5)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 19, 249 | "metadata": {}, 250 | "outputs": [ 251 | { 252 | "name": "stdout", 253 | "output_type": "stream", 254 | "text": [ 255 | "Enter a number: 1\n", 256 | "8\n" 257 | ] 258 | } 259 | ], 260 | "source": [ 261 | "a = int(input(\"Enter a number: \"))\n", 262 | "\n", 263 | "if a > 4:\n", 264 | " print(1)\n", 265 | " if a == 5:\n", 266 | " print(2)\n", 267 | " if a < 3:\n", 268 | " print(3)\n", 269 | " elif a > 4:\n", 270 | " print(4)\n", 271 | " elif a == 7:\n", 272 | " print(5)\n", 273 | " if a != 7:\n", 274 | " print(6)\n", 275 | " else:\n", 276 | " print(7)\n", 277 | "else:\n", 278 | " if a == 1:\n", 279 | " print(8)\n", 280 | " else:\n", 281 | " print(9)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": {}, 287 | "source": [ 288 | "### Ternary Statements" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | " ? : # ternary operator" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 20, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "name": "stdout", 307 | "output_type": "stream", 308 | "text": [ 309 | "5\n" 310 | ] 311 | } 312 | ], 313 | "source": [ 314 | "a = 10\n", 315 | "\n", 316 | "b = 5 if a == 10 else 45\n", 317 | "\n", 318 | "print(b)" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 21, 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "name": "stdout", 328 | "output_type": "stream", 329 | "text": [ 330 | "45\n" 331 | ] 332 | } 333 | ], 334 | "source": [ 335 | "a = 10\n", 336 | "\n", 337 | "b = 5 if a > 11 else 45\n", 338 | "\n", 339 | "print(b)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 22, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "Login\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "status = 1\n", 357 | "\n", 358 | "msg = \"Login\" if status == 1 else \"Logout\"\n", 359 | "\n", 360 | "print(msg)" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "metadata": {}, 366 | "source": [ 367 | "**WAP to enter a number from user and print its absolute value**" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": null, 373 | "metadata": {}, 374 | "outputs": [], 375 | "source": [ 376 | "-1 => 1\n", 377 | "-3 => 3" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 25, 383 | "metadata": {}, 384 | "outputs": [ 385 | { 386 | "name": "stdout", 387 | "output_type": "stream", 388 | "text": [ 389 | "Enter a Number: 0\n", 390 | "0\n" 391 | ] 392 | } 393 | ], 394 | "source": [ 395 | "n = int(input(\"Enter a Number: \"))\n", 396 | "\n", 397 | "if n < 0:\n", 398 | " print( n * (-1) )\n", 399 | "else:\n", 400 | " print(n)" 401 | ] 402 | }, 403 | { 404 | "cell_type": "markdown", 405 | "metadata": {}, 406 | "source": [ 407 | "**WAP to enter single digit from user and print its character format**" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": null, 413 | "metadata": {}, 414 | "outputs": [], 415 | "source": [ 416 | "5\n", 417 | "Five" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [ 426 | "n = int(input(\"Enter a number\"))\n", 427 | "\n", 428 | "if n == 1:\n", 429 | " print(\"One\")\n", 430 | "elif n == 2:\n", 431 | " print(\"Two\")" 432 | ] 433 | }, 434 | { 435 | "cell_type": "markdown", 436 | "metadata": {}, 437 | "source": [ 438 | "**WAP to enter a character from user and check if it is vowel or consonant**" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": {}, 445 | "outputs": [], 446 | "source": [ 447 | "a\n", 448 | "Vowel" 449 | ] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "execution_count": null, 454 | "metadata": {}, 455 | "outputs": [], 456 | "source": [ 457 | "n = input()\n", 458 | "\n", 459 | "if n == 'a':\n", 460 | " print(\"vowel\")\n", 461 | "elif n == 'e':\n", 462 | " print(\"vowel\")\n", 463 | ".\n", 464 | ".\n", 465 | ".\n", 466 | "else:\n", 467 | " print(\"consonant\")" 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 2, 473 | "metadata": {}, 474 | "outputs": [ 475 | { 476 | "name": "stdout", 477 | "output_type": "stream", 478 | "text": [ 479 | "Enter a characterk\n", 480 | "consonant\n" 481 | ] 482 | } 483 | ], 484 | "source": [ 485 | "n = input(\"Enter a character\")\n", 486 | "\n", 487 | "if n == 'a' or n == 'e' or n == 'i' or n == 'o' or n == 'u':\n", 488 | " print(\"vowel\")\n", 489 | "else:\n", 490 | " print(\"consonant\")" 491 | ] 492 | }, 493 | { 494 | "cell_type": "code", 495 | "execution_count": 4, 496 | "metadata": {}, 497 | "outputs": [ 498 | { 499 | "ename": "SyntaxError", 500 | "evalue": "invalid syntax (, line 3)", 501 | "output_type": "error", 502 | "traceback": [ 503 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m if n == 'a' || n == 'e' || n == 'i' || n == 'o' || n == 'u':\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 504 | ] 505 | } 506 | ], 507 | "source": [ 508 | "n = input(\"Enter a character\")\n", 509 | "\n", 510 | "if n == 'a' | n == 'e' | n == 'i' | n == 'o' | n == 'u':\n", 511 | " print(\"vowel\")\n", 512 | "else:\n", 513 | " print(\"consonant\")" 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "execution_count": null, 519 | "metadata": {}, 520 | "outputs": [], 521 | "source": [] 522 | } 523 | ], 524 | "metadata": { 525 | "kernelspec": { 526 | "display_name": "Python 3", 527 | "language": "python", 528 | "name": "python3" 529 | }, 530 | "language_info": { 531 | "codemirror_mode": { 532 | "name": "ipython", 533 | "version": 3 534 | }, 535 | "file_extension": ".py", 536 | "mimetype": "text/x-python", 537 | "name": "python", 538 | "nbconvert_exporter": "python", 539 | "pygments_lexer": "ipython3", 540 | "version": "3.7.6" 541 | } 542 | }, 543 | "nbformat": 4, 544 | "nbformat_minor": 4 545 | } 546 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/5_While Loop-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 4 6 | } 7 | -------------------------------------------------------------------------------- /1_Python Introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "!jt -t chesterish" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# 1 | Introduction and Basics\n", 17 | "\n", 18 | "First session Theory\n", 19 | "\n", 20 | "1. Installation\n", 21 | "2. Python Org, Python 3\n", 22 | "3. Variables\n", 23 | "4. Print function\n", 24 | "5. Input from user\n", 25 | "6. Data Types\n", 26 | "7. Type Conversion\n", 27 | "8. First Program\n" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "Hello World\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "print(\"Hello World\")" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 2, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Hello\n", 57 | "World\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "# \\n - new line character\n", 63 | "\n", 64 | "print(\"Hello\\nWorld\")" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 3, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "name": "stdout", 74 | "output_type": "stream", 75 | "text": [ 76 | "Hello\tWorld\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "# \\t - horizontal tab\n", 82 | "\n", 83 | "print(\"Hello\\tWorld\")" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "## Basic Questions" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "name\n", 100 | " college\n", 101 | " city" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 4, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "Himanshu\n", 114 | "\tDAVV\n", 115 | "\t\tIndore\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "print(\"Himanshu\\n\\tDAVV\\n\\t\\tIndore\")" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "*\n", 130 | "**\n", 131 | "***" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 5, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "*\n", 144 | "**\n", 145 | "***\n" 146 | ] 147 | } 148 | ], 149 | "source": [ 150 | "print(\"*\\n**\\n***\")" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [ 159 | " *\n", 160 | "* *\n", 161 | " *" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 7, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | " *\n", 174 | "*\t*\n", 175 | " *\n" 176 | ] 177 | } 178 | ], 179 | "source": [ 180 | "print(\" *\\n*\\t*\\n *\")" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "# Variables" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 8, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "10\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "a = 10\n", 205 | "\n", 206 | "print(a)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 9, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "name": "stdout", 216 | "output_type": "stream", 217 | "text": [ 218 | "10.5\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "b = 10.5\n", 224 | "\n", 225 | "print(b)" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 10, 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "name": "stdout", 235 | "output_type": "stream", 236 | "text": [ 237 | "Indore\n" 238 | ] 239 | } 240 | ], 241 | "source": [ 242 | "c = \"Indore\"\n", 243 | "\n", 244 | "print(c)" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "metadata": {}, 250 | "source": [ 251 | "## type function" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 12, 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "name": "stdout", 261 | "output_type": "stream", 262 | "text": [ 263 | "10\n", 264 | "\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "print(a)\n", 270 | "\n", 271 | "print(type(a))" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 14, 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "10.5\n", 284 | "\n" 285 | ] 286 | } 287 | ], 288 | "source": [ 289 | "print(b)\n", 290 | "\n", 291 | "print(type(b))" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 16, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "Indore\n", 304 | "\n" 305 | ] 306 | } 307 | ], 308 | "source": [ 309 | "print(c)\n", 310 | "\n", 311 | "print(type(c))" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 17, 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "name": "stdout", 321 | "output_type": "stream", 322 | "text": [ 323 | "15\n", 324 | "10\n" 325 | ] 326 | } 327 | ], 328 | "source": [ 329 | "a = 10\n", 330 | "\n", 331 | "print(a + 5)\n", 332 | "\n", 333 | "print(a)" 334 | ] 335 | }, 336 | { 337 | "cell_type": "markdown", 338 | "metadata": {}, 339 | "source": [ 340 | "# User Input" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": 18, 346 | "metadata": {}, 347 | "outputs": [ 348 | { 349 | "name": "stdout", 350 | "output_type": "stream", 351 | "text": [ 352 | "10\n", 353 | "10\n" 354 | ] 355 | } 356 | ], 357 | "source": [ 358 | "x = input()\n", 359 | "#x = 10\n", 360 | "\n", 361 | "print(x)" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 20, 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "name": "stdout", 371 | "output_type": "stream", 372 | "text": [ 373 | "Enter Your Name: Himanshu\n", 374 | "Himanshu\n" 375 | ] 376 | } 377 | ], 378 | "source": [ 379 | "x = input(\"Enter Your Name: \")\n", 380 | "\n", 381 | "print(x)" 382 | ] 383 | }, 384 | { 385 | "cell_type": "code", 386 | "execution_count": 21, 387 | "metadata": {}, 388 | "outputs": [ 389 | { 390 | "name": "stdout", 391 | "output_type": "stream", 392 | "text": [ 393 | "Enter Your Name: Himanshu\n", 394 | "Hello Himanshu\n" 395 | ] 396 | } 397 | ], 398 | "source": [ 399 | "x = input(\"Enter Your Name: \")\n", 400 | "\n", 401 | "print(\"Hello\",x)" 402 | ] 403 | }, 404 | { 405 | "cell_type": "markdown", 406 | "metadata": {}, 407 | "source": [ 408 | "# First Program\n", 409 | "\n", 410 | "WAP to enter 2 numbers from user and print sum of them." 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "execution_count": 22, 416 | "metadata": {}, 417 | "outputs": [ 418 | { 419 | "name": "stdout", 420 | "output_type": "stream", 421 | "text": [ 422 | "Enter 1st number: 10\n", 423 | "Enter 2nd number: 20\n", 424 | "1020\n" 425 | ] 426 | } 427 | ], 428 | "source": [ 429 | "a = input(\"Enter 1st number: \")\n", 430 | "b = input(\"Enter 2nd number: \")\n", 431 | "\n", 432 | "c = a + b\n", 433 | "\n", 434 | "print(c)" 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": 23, 440 | "metadata": {}, 441 | "outputs": [ 442 | { 443 | "data": { 444 | "text/plain": [ 445 | "'1020'" 446 | ] 447 | }, 448 | "execution_count": 23, 449 | "metadata": {}, 450 | "output_type": "execute_result" 451 | } 452 | ], 453 | "source": [ 454 | "\"10\" + \"20\"" 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": 25, 460 | "metadata": {}, 461 | "outputs": [ 462 | { 463 | "name": "stdout", 464 | "output_type": "stream", 465 | "text": [ 466 | "\n" 467 | ] 468 | } 469 | ], 470 | "source": [ 471 | "print(type(a))" 472 | ] 473 | }, 474 | { 475 | "cell_type": "markdown", 476 | "metadata": {}, 477 | "source": [ 478 | "# Type Casting" 479 | ] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": 26, 484 | "metadata": {}, 485 | "outputs": [ 486 | { 487 | "name": "stdout", 488 | "output_type": "stream", 489 | "text": [ 490 | "\n", 491 | "10\n", 492 | "\n" 493 | ] 494 | } 495 | ], 496 | "source": [ 497 | "a = 10.5\n", 498 | "print(type(a))\n", 499 | "\n", 500 | "b = int(a)\n", 501 | "\n", 502 | "print(b)\n", 503 | "print(type(b))" 504 | ] 505 | }, 506 | { 507 | "cell_type": "code", 508 | "execution_count": 27, 509 | "metadata": {}, 510 | "outputs": [ 511 | { 512 | "name": "stdout", 513 | "output_type": "stream", 514 | "text": [ 515 | "Enter 1st number: 10\n", 516 | "Enter 2nd number: 20\n", 517 | "30\n" 518 | ] 519 | } 520 | ], 521 | "source": [ 522 | "a = int(input(\"Enter 1st number: \"))\n", 523 | "b = int(input(\"Enter 2nd number: \"))\n", 524 | "\n", 525 | "c = a + b\n", 526 | "\n", 527 | "print(c)" 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 28, 533 | "metadata": {}, 534 | "outputs": [ 535 | { 536 | "name": "stdout", 537 | "output_type": "stream", 538 | "text": [ 539 | "Enter 1st number: 10\n", 540 | "Enter 2nd number: 20\n", 541 | "Addition = 30\n" 542 | ] 543 | } 544 | ], 545 | "source": [ 546 | "a = int(input(\"Enter 1st number: \"))\n", 547 | "b = int(input(\"Enter 2nd number: \"))\n", 548 | "\n", 549 | "c = a + b\n", 550 | "\n", 551 | "print(\"Addition =\",c)" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "execution_count": null, 557 | "metadata": {}, 558 | "outputs": [], 559 | "source": [] 560 | } 561 | ], 562 | "metadata": { 563 | "kernelspec": { 564 | "display_name": "Python 3", 565 | "language": "python", 566 | "name": "python3" 567 | }, 568 | "language_info": { 569 | "codemirror_mode": { 570 | "name": "ipython", 571 | "version": 3 572 | }, 573 | "file_extension": ".py", 574 | "mimetype": "text/x-python", 575 | "name": "python", 576 | "nbconvert_exporter": "python", 577 | "pygments_lexer": "ipython3", 578 | "version": "3.7.6" 579 | } 580 | }, 581 | "nbformat": 4, 582 | "nbformat_minor": 4 583 | } 584 | -------------------------------------------------------------------------------- /21_Tuples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuple\n", 8 | "Tuples Basics\n", 9 | "\n", 10 | "Tuples Comprehensions / Slicing\n", 11 | "\n", 12 | "Tuple Functions\n", 13 | "\n", 14 | "Tuple Methods" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "(1, 2, 3, 'A')\n", 27 | "\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "t = (1,2,3,\"A\") # immutable\n", 33 | "\n", 34 | "print(t)\n", 35 | "\n", 36 | "print(type(t))" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "ename": "TypeError", 46 | "evalue": "'tuple' object does not support item assignment", 47 | "output_type": "error", 48 | "traceback": [ 49 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 50 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 51 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 52 | "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "t[0] = 10" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "1\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "print(t[0])" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "A\n" 87 | ] 88 | } 89 | ], 90 | "source": [ 91 | "print(t[3])" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "('one', 'two', 'three')\n", 104 | "\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "my = \"one\", \"two\", \"three\"\n", 110 | "\n", 111 | "print(my)\n", 112 | "\n", 113 | "print(type(my))" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 7, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "three\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "print(my[2])" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 8, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "()\n", 143 | "\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "t = ()\n", 149 | "\n", 150 | "print(t)\n", 151 | "\n", 152 | "print(type(t))" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 11, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "10\n", 165 | "\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "t = (10)\n", 171 | "\n", 172 | "print(t)\n", 173 | "\n", 174 | "print(type(t))" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 12, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "(10,)\n", 187 | "\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "t = (10,)\n", 193 | "\n", 194 | "print(t)\n", 195 | "\n", 196 | "print(type(t))" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "# Tuple Unpacking" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": null, 209 | "metadata": {}, 210 | "outputs": [], 211 | "source": [ 212 | "n = (1,2,3)\n", 213 | "\n", 214 | "a,b,c = n\n", 215 | "\n", 216 | "print" 217 | ] 218 | } 219 | ], 220 | "metadata": { 221 | "kernelspec": { 222 | "display_name": "Python 3", 223 | "language": "python", 224 | "name": "python3" 225 | }, 226 | "language_info": { 227 | "codemirror_mode": { 228 | "name": "ipython", 229 | "version": 3 230 | }, 231 | "file_extension": ".py", 232 | "mimetype": "text/x-python", 233 | "name": "python", 234 | "nbconvert_exporter": "python", 235 | "pygments_lexer": "ipython3", 236 | "version": "3.7.6" 237 | } 238 | }, 239 | "nbformat": 4, 240 | "nbformat_minor": 4 241 | } 242 | -------------------------------------------------------------------------------- /23_Object Oriented Programming.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object-Oriented Programming\n", 8 | "Classes\n", 9 | "\n", 10 | "Objects\n", 11 | "\n", 12 | "Method Calls\n", 13 | "\n", 14 | "Inheritance and Its Types\n", 15 | "\n", 16 | "Overloading\n", 17 | "\n", 18 | "Overriding\n", 19 | "\n", 20 | "Data Hiding\n", 21 | "\n", 22 | "Operator Overloading" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# OOPs\n", 30 | "\n", 31 | "7 Properties of OOPs\n", 32 | "\n", 33 | "1. Class\n", 34 | " \n", 35 | " Updated version of structure (struct C programming).\n", 36 | " Collection of variables and methods.\n", 37 | " Class is a blueprint.\n", 38 | "2. Object\n", 39 | " Run time or real time entity.\n", 40 | " hash code - id()\n", 41 | " \n", 42 | "3. Inheritance\n", 43 | " " 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "int a = 10; # 2 bytes\n", 53 | "\n", 54 | "struct abc{\n", 55 | " int a;\n", 56 | " float b;\n", 57 | " char c;\n", 58 | "}" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 1, 64 | "metadata": {}, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "10\n", 71 | "94405754090528\n" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "a = 10\n", 77 | "\n", 78 | "print(a)\n", 79 | "\n", 80 | "print(id(a))" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [] 89 | } 90 | ], 91 | "metadata": { 92 | "kernelspec": { 93 | "display_name": "Python 3", 94 | "language": "python", 95 | "name": "python3" 96 | }, 97 | "language_info": { 98 | "codemirror_mode": { 99 | "name": "ipython", 100 | "version": 3 101 | }, 102 | "file_extension": ".py", 103 | "mimetype": "text/x-python", 104 | "name": "python", 105 | "nbconvert_exporter": "python", 106 | "pygments_lexer": "ipython3", 107 | "version": "3.7.6" 108 | } 109 | }, 110 | "nbformat": 4, 111 | "nbformat_minor": 4 112 | } 113 | -------------------------------------------------------------------------------- /24_Object Oriented Programming.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object-Oriented Programming\n", 8 | "Classes\n", 9 | "\n", 10 | "Objects\n", 11 | "\n", 12 | "Method Calls\n", 13 | "\n", 14 | "Inheritance and Its Types\n", 15 | "\n", 16 | "Overloading\n", 17 | "\n", 18 | "Overriding\n", 19 | "\n", 20 | "Data Hiding\n", 21 | "\n", 22 | "Operator Overloading" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# OOPs\n", 30 | "\n", 31 | "7 Properties of OOPs\n", 32 | "\n", 33 | "1. Class\n", 34 | " \n", 35 | " Updated version of structure (struct C programming).\n", 36 | " Collection of variables and methods.\n", 37 | " Class is a blueprint.\n", 38 | "2. Object\n", 39 | " Run time or real time entity.\n", 40 | " hash code - id()\n", 41 | " \n", 42 | "3. Abstraction and Encapsulation\n", 43 | " Abstraction - Showing only essential features without showing any backgroud details.\n", 44 | " Encapsulation - Wrapping up of data in a single unit.\n", 45 | " \n", 46 | "4. Inheritance\n", 47 | " Acquiring properties of one class into another.\n", 48 | " Code reuse\n", 49 | " Types - \n", 50 | " - single level\n", 51 | " - multilevel \n", 52 | " - hierarchical \n", 53 | " - multiple\n", 54 | " - hybrid\n", 55 | "5. Polymorphism\n", 56 | " Same name multiple functionalities\n", 57 | " - Method overloading\n", 58 | " - method overriding\n", 59 | " add()\n", 60 | " add(x, y)\n", 61 | " add(a,b,c)\n", 62 | " add()\n", 63 | "6. Dynamic Memory Allocation\n", 64 | " run time memory allocation / late binding / dynamic binding\n", 65 | "7. Message Passing\n", 66 | " communication between objects." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "int a = 10; # 2 bytes\n", 76 | "\n", 77 | "struct abc{\n", 78 | " int a;\n", 79 | " float b;\n", 80 | " char c;\n", 81 | "}" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "name": "stdout", 91 | "output_type": "stream", 92 | "text": [ 93 | "10\n", 94 | "94405754090528\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "a = 10\n", 100 | "\n", 101 | "print(a)\n", 102 | "\n", 103 | "print(id(a))" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "windows xp\n", 113 | "\n", 114 | "windows 7\n", 115 | "^\n", 116 | "|\n", 117 | "windows 10" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 5, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "class Cricket:\n", 127 | " \n", 128 | " def bat(self):\n", 129 | " print(\"Batting\")\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 6, 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "name": "stdout", 139 | "output_type": "stream", 140 | "text": [ 141 | "Batting\n" 142 | ] 143 | } 144 | ], 145 | "source": [ 146 | "c = Cricket()\n", 147 | "\n", 148 | "c.bat()" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": 7, 154 | "metadata": {}, 155 | "outputs": [ 156 | { 157 | "name": "stdout", 158 | "output_type": "stream", 159 | "text": [ 160 | "<__main__.Cricket object at 0x7f64641321d0>\n" 161 | ] 162 | } 163 | ], 164 | "source": [ 165 | "print(c)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 8, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "140069152432592\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "print(id(c))" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 9, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "<__main__.Cricket object at 0x7f6464132f90>\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "print(Cricket())" 200 | ] 201 | }, 202 | { 203 | "cell_type": "code", 204 | "execution_count": 10, 205 | "metadata": {}, 206 | "outputs": [ 207 | { 208 | "name": "stdout", 209 | "output_type": "stream", 210 | "text": [ 211 | "Baller\n", 212 | "<__main__.Baller object at 0x7f646412d290>\n", 213 | "<__main__.Baller object at 0x7f646412d290>\n" 214 | ] 215 | } 216 | ], 217 | "source": [ 218 | "class Baller:\n", 219 | " \n", 220 | " def bat(self): # self = c\n", 221 | " print(\"Baller\")\n", 222 | " print(self)\n", 223 | "\n", 224 | "c = Baller()\n", 225 | "\n", 226 | "c.bat()\n", 227 | "print(c)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": null, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "TV Blueprint - class\n", 237 | "- smart tv\n", 238 | "- colors\n", 239 | "- usb\n", 240 | "- hdmi\n", 241 | "- wifi\n", 242 | "\n", 243 | "Actual TV - object\n", 244 | "\n", 245 | "remote - reference" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": null, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": null, 258 | "metadata": {}, 259 | "outputs": [], 260 | "source": [] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": null, 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "metadata": {}, 273 | "outputs": [], 274 | "source": [] 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.7.6" 294 | } 295 | }, 296 | "nbformat": 4, 297 | "nbformat_minor": 4 298 | } 299 | -------------------------------------------------------------------------------- /28_Python File Handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# File Handling\n", 8 | "\n", 9 | "1. Read\n", 10 | "2. Write\n", 11 | "3. Append" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "## Read a file" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "<_io.TextIOWrapper name='student.txt' mode='r' encoding='UTF-8'>\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "f = open(\"student.txt\")\n", 36 | "\n", 37 | "print(f)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "this is a city file.\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "f = open(\"student.txt\", 'r')\n", 55 | "\n", 56 | "print(f.read())" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "print(type(f))" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 4, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "print(type(f.read()))" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "f.close()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "### number of characters" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "Help on built-in function read:\n", 119 | "\n", 120 | "read(size=-1, /) method of _io.TextIOWrapper instance\n", 121 | " Read at most n characters from stream.\n", 122 | " \n", 123 | " Read from underlying buffer until we have n characters or we hit EOF.\n", 124 | " If n is negative or omitted, read until EOF.\n", 125 | "\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "help(f.read)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 7, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "this \n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "f = open(\"student.txt\", 'r')\n", 148 | "\n", 149 | "print(f.read(5))" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 8, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stdout", 159 | "output_type": "stream", 160 | "text": [ 161 | "this is a city file.\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "f = open(\"student.txt\", 'r')\n", 167 | "\n", 168 | "print(f.readline())" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 10, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "['this is a city file.\\n', 'I m from India.']\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "f = open(\"student.txt\", 'r')\n", 186 | "\n", 187 | "print(f.readlines())" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 11, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "I m from India.\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "f = open(\"student.txt\", 'r')\n", 205 | "\n", 206 | "print(f.readlines()[1])" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": null, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [] 215 | } 216 | ], 217 | "metadata": { 218 | "kernelspec": { 219 | "display_name": "Python 3", 220 | "language": "python", 221 | "name": "python3" 222 | }, 223 | "language_info": { 224 | "codemirror_mode": { 225 | "name": "ipython", 226 | "version": 3 227 | }, 228 | "file_extension": ".py", 229 | "mimetype": "text/x-python", 230 | "name": "python", 231 | "nbconvert_exporter": "python", 232 | "pygments_lexer": "ipython3", 233 | "version": "3.7.6" 234 | } 235 | }, 236 | "nbformat": 4, 237 | "nbformat_minor": 4 238 | } 239 | -------------------------------------------------------------------------------- /29_Python File Handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# File Handling\n", 8 | "\n", 9 | "1. Read\n", 10 | "2. Write\n", 11 | "3. Append" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "## Read a file" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 1, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "name": "stdout", 28 | "output_type": "stream", 29 | "text": [ 30 | "<_io.TextIOWrapper name='student.txt' mode='r' encoding='UTF-8'>\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "f = open(\"student.txt\")\n", 36 | "\n", 37 | "print(f)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 2, 43 | "metadata": {}, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "this is a city file.\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "f = open(\"student.txt\", 'r')\n", 55 | "\n", 56 | "print(f.read())" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 3, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "print(type(f))" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 4, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "name": "stdout", 83 | "output_type": "stream", 84 | "text": [ 85 | "\n" 86 | ] 87 | } 88 | ], 89 | "source": [ 90 | "print(type(f.read()))" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 5, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "f.close()" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "### number of characters" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 6, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "Help on built-in function read:\n", 119 | "\n", 120 | "read(size=-1, /) method of _io.TextIOWrapper instance\n", 121 | " Read at most n characters from stream.\n", 122 | " \n", 123 | " Read from underlying buffer until we have n characters or we hit EOF.\n", 124 | " If n is negative or omitted, read until EOF.\n", 125 | "\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "help(f.read)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 7, 136 | "metadata": {}, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "this \n" 143 | ] 144 | } 145 | ], 146 | "source": [ 147 | "f = open(\"student.txt\", 'r')\n", 148 | "\n", 149 | "print(f.read(5))" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 8, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "name": "stdout", 159 | "output_type": "stream", 160 | "text": [ 161 | "this is a city file.\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "f = open(\"student.txt\", 'r')\n", 167 | "\n", 168 | "print(f.readline())" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 10, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "['this is a city file.\\n', 'I m from India.']\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "f = open(\"student.txt\", 'r')\n", 186 | "\n", 187 | "print(f.readlines())" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 11, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "I m from India.\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "f = open(\"student.txt\", 'r')\n", 205 | "\n", 206 | "print(f.readlines()[1])" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "### using a loop" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 1, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "this is a city file.\n", 226 | "\n", 227 | "I m from India.\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "f = open(\"student.txt\", 'r')\n", 233 | "\n", 234 | "for i in f:\n", 235 | " print(i)\n", 236 | "\n", 237 | "f.close()" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 2, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "name": "stdout", 247 | "output_type": "stream", 248 | "text": [ 249 | "2\n" 250 | ] 251 | } 252 | ], 253 | "source": [ 254 | "print(len(open(\"student.txt\", 'r').readlines()))" 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": 4, 260 | "metadata": {}, 261 | "outputs": [ 262 | { 263 | "ename": "FileNotFoundError", 264 | "evalue": "[Errno 2] No such file or directory: 'hello.txt'", 265 | "output_type": "error", 266 | "traceback": [ 267 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 268 | "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", 269 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello.txt\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 270 | "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'hello.txt'" 271 | ] 272 | } 273 | ], 274 | "source": [ 275 | "print(len(open(\"hello.txt\", 'r')))" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 3, 281 | "metadata": { 282 | "scrolled": true 283 | }, 284 | "outputs": [ 285 | { 286 | "ename": "TypeError", 287 | "evalue": "object of type '_io.TextIOWrapper' has no len()", 288 | "output_type": "error", 289 | "traceback": [ 290 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 291 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 292 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"student.txt\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'r'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 293 | "\u001b[0;31mTypeError\u001b[0m: object of type '_io.TextIOWrapper' has no len()" 294 | ] 295 | } 296 | ], 297 | "source": [ 298 | "print(len(open(\"student.txt\", 'r')))" 299 | ] 300 | }, 301 | { 302 | "cell_type": "markdown", 303 | "metadata": {}, 304 | "source": [ 305 | "### write a file" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": 5, 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "f = open(\"mumbai.txt\", 'w')\n", 315 | "\n", 316 | "f.write('This is a virus.')\n", 317 | "\n", 318 | "f.close()" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 6, 324 | "metadata": {}, 325 | "outputs": [], 326 | "source": [ 327 | "f = open(\"student.txt\", 'w')\n", 328 | "\n", 329 | "f.close()" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 7, 335 | "metadata": {}, 336 | "outputs": [ 337 | { 338 | "name": "stdout", 339 | "output_type": "stream", 340 | "text": [ 341 | "This is a virus.\n" 342 | ] 343 | } 344 | ], 345 | "source": [ 346 | "f = open(\"mumbai.txt\", 'r')\n", 347 | "\n", 348 | "print(f.read())\n", 349 | "\n", 350 | "f.close()" 351 | ] 352 | }, 353 | { 354 | "cell_type": "code", 355 | "execution_count": 8, 356 | "metadata": {}, 357 | "outputs": [ 358 | { 359 | "name": "stdout", 360 | "output_type": "stream", 361 | "text": [ 362 | "spiderman is the new ironman\n" 363 | ] 364 | } 365 | ], 366 | "source": [ 367 | "s = \"spiderman is the new ironman\"\n", 368 | "\n", 369 | "f = open(\"queens.txt\", 'w')\n", 370 | "\n", 371 | "f.write(s)\n", 372 | "\n", 373 | "f.close()\n", 374 | "\n", 375 | "f = open(\"queens.txt\", 'r')\n", 376 | "print(f.read())\n", 377 | "\n", 378 | "f.close()" 379 | ] 380 | }, 381 | { 382 | "cell_type": "markdown", 383 | "metadata": {}, 384 | "source": [ 385 | "### append a file\n", 386 | "\n", 387 | "edit a file" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": 9, 393 | "metadata": {}, 394 | "outputs": [], 395 | "source": [ 396 | "f = open(\"queens.txt\", 'a')\n", 397 | "\n", 398 | "f.write('\\nThis is a virus.')\n", 399 | "\n", 400 | "f.close()" 401 | ] 402 | }, 403 | { 404 | "cell_type": "markdown", 405 | "metadata": {}, 406 | "source": [ 407 | "## with statement" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 10, 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "spiderman is the new ironman\n", 420 | "This is a virus.\n" 421 | ] 422 | } 423 | ], 424 | "source": [ 425 | "with open(\"queens.txt\",'r') as p:\n", 426 | " print(p.read())" 427 | ] 428 | }, 429 | { 430 | "cell_type": "markdown", 431 | "metadata": {}, 432 | "source": [ 433 | "**WAP to open a file and find the largest word in it**" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "metadata": {}, 439 | "source": [ 440 | "**WAP to check a file is closed or not.**" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 16, 446 | "metadata": {}, 447 | "outputs": [], 448 | "source": [ 449 | "f = open(\"student.txt\", 'r')\n", 450 | "f.close()" 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 17, 456 | "metadata": {}, 457 | "outputs": [ 458 | { 459 | "name": "stdout", 460 | "output_type": "stream", 461 | "text": [ 462 | "Hi\n" 463 | ] 464 | } 465 | ], 466 | "source": [ 467 | "if f.closed:\n", 468 | " print(\"Hi\")" 469 | ] 470 | }, 471 | { 472 | "cell_type": "code", 473 | "execution_count": null, 474 | "metadata": {}, 475 | "outputs": [], 476 | "source": [] 477 | }, 478 | { 479 | "cell_type": "code", 480 | "execution_count": null, 481 | "metadata": {}, 482 | "outputs": [], 483 | "source": [] 484 | } 485 | ], 486 | "metadata": { 487 | "kernelspec": { 488 | "display_name": "Python 3", 489 | "language": "python", 490 | "name": "python3" 491 | }, 492 | "language_info": { 493 | "codemirror_mode": { 494 | "name": "ipython", 495 | "version": 3 496 | }, 497 | "file_extension": ".py", 498 | "mimetype": "text/x-python", 499 | "name": "python", 500 | "nbconvert_exporter": "python", 501 | "pygments_lexer": "ipython3", 502 | "version": "3.7.6" 503 | } 504 | }, 505 | "nbformat": 4, 506 | "nbformat_minor": 4 507 | } 508 | -------------------------------------------------------------------------------- /2_Operators.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2 | Operators\n", 8 | "\n", 9 | "1. Arithmetic Operators\n", 10 | "2. Relational Operators\n", 11 | "3. Bitwise Operators\n", 12 | "4. Logical Operators\n", 13 | "5. Assignment Operators\n", 14 | "6. Compound Operators\n", 15 | "7. Membership Operators\n", 16 | "8. Identity Operators" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 1, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "1\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "# Arithmetic Operators\n", 34 | "# + - * / % // **\n", 35 | "\n", 36 | "print(7 % 2) # modulo" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 2, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "3\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "print(11 % 4)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 3, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "3\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "print(7 // 2) # floor division" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 4, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "2\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "print(10 // 4)" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 5, 93 | "metadata": {}, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "9\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "print(3 ** 2) # exponents" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": 6, 110 | "metadata": {}, 111 | "outputs": [ 112 | { 113 | "name": "stdout", 114 | "output_type": "stream", 115 | "text": [ 116 | "343\n" 117 | ] 118 | } 119 | ], 120 | "source": [ 121 | "print(7 ** 3)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 7, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "True\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "# Relational Operators\n", 139 | "# >, <, >= , <=, ==, !=\n", 140 | "\n", 141 | "print(10 > 5)" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 8, 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "False\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "print(10 < 10)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 9, 164 | "metadata": {}, 165 | "outputs": [ 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "True\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "print(10 >= 10)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 10, 181 | "metadata": {}, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "True\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "print(10 == 10)" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 11, 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "True\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "print(11 != 5)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": null, 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "# Boolean Operators\n", 219 | "\n", 220 | "True --- 1\n", 221 | "\n", 222 | "False --- 0" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": null, 228 | "metadata": {}, 229 | "outputs": [], 230 | "source": [ 231 | "# Logical Operator\n", 232 | "\n", 233 | "not\n", 234 | "and\n", 235 | "or" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 12, 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "False\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "print(not True)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "code", 257 | "execution_count": 13, 258 | "metadata": {}, 259 | "outputs": [ 260 | { 261 | "name": "stdout", 262 | "output_type": "stream", 263 | "text": [ 264 | "True\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "print(not False)" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 14, 275 | "metadata": {}, 276 | "outputs": [ 277 | { 278 | "name": "stdout", 279 | "output_type": "stream", 280 | "text": [ 281 | "False\n" 282 | ] 283 | } 284 | ], 285 | "source": [ 286 | "print(not (10 == 10))" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [ 295 | "# and \n", 296 | "# truth table\n", 297 | "\n", 298 | "0 and 0 = 0\n", 299 | "0 and 1 = 0\n", 300 | "1 and 0 = 0\n", 301 | "1 and 1 = 1" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 15, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "False\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "print(False and True)" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 16, 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "name": "stdout", 328 | "output_type": "stream", 329 | "text": [ 330 | "True\n" 331 | ] 332 | } 333 | ], 334 | "source": [ 335 | "print(True and True)" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": null, 341 | "metadata": {}, 342 | "outputs": [], 343 | "source": [ 344 | "# or \n", 345 | "# truth table\n", 346 | "\n", 347 | "0 or 0 = 0\n", 348 | "0 or 1 = 1\n", 349 | "1 or 0 = 1\n", 350 | "1 or 1 = 1" 351 | ] 352 | }, 353 | { 354 | "cell_type": "code", 355 | "execution_count": 17, 356 | "metadata": {}, 357 | "outputs": [ 358 | { 359 | "name": "stdout", 360 | "output_type": "stream", 361 | "text": [ 362 | "True\n" 363 | ] 364 | } 365 | ], 366 | "source": [ 367 | "print(True or False)" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 18, 373 | "metadata": {}, 374 | "outputs": [ 375 | { 376 | "name": "stdout", 377 | "output_type": "stream", 378 | "text": [ 379 | "False\n" 380 | ] 381 | } 382 | ], 383 | "source": [ 384 | "print(True and False or not True and not False)\n", 385 | "# False True\n", 386 | "# False False\n", 387 | "#False" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": null, 393 | "metadata": {}, 394 | "outputs": [], 395 | "source": [ 396 | "# Assignment Operators\n", 397 | " = \n", 398 | "# Compound Operators\n", 399 | "+= , -=, *= , /=, %=, //= , **=" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 19, 405 | "metadata": {}, 406 | "outputs": [ 407 | { 408 | "name": "stdout", 409 | "output_type": "stream", 410 | "text": [ 411 | "15\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "a = 10\n", 417 | "\n", 418 | "a += 5 # a = a + 5\n", 419 | "\n", 420 | "print(a)" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": 20, 426 | "metadata": {}, 427 | "outputs": [ 428 | { 429 | "name": "stdout", 430 | "output_type": "stream", 431 | "text": [ 432 | "11\n" 433 | ] 434 | } 435 | ], 436 | "source": [ 437 | "a = 10\n", 438 | "\n", 439 | "a += 1 # a = a + 1\n", 440 | "\n", 441 | "print(a)" 442 | ] 443 | }, 444 | { 445 | "cell_type": "code", 446 | "execution_count": 21, 447 | "metadata": {}, 448 | "outputs": [ 449 | { 450 | "name": "stdout", 451 | "output_type": "stream", 452 | "text": [ 453 | "2\n" 454 | ] 455 | } 456 | ], 457 | "source": [ 458 | "a = 10\n", 459 | "\n", 460 | "a %= 4 # a = a % 4\n", 461 | "\n", 462 | "print(a)" 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": 22, 468 | "metadata": {}, 469 | "outputs": [ 470 | { 471 | "name": "stdout", 472 | "output_type": "stream", 473 | "text": [ 474 | "100\n" 475 | ] 476 | } 477 | ], 478 | "source": [ 479 | "a = 10\n", 480 | "\n", 481 | "a **= 2 # a = a ** 2\n", 482 | "\n", 483 | "print(a)" 484 | ] 485 | }, 486 | { 487 | "cell_type": "code", 488 | "execution_count": null, 489 | "metadata": {}, 490 | "outputs": [], 491 | "source": [ 492 | "# membership operators\n", 493 | "in\n", 494 | "not in" 495 | ] 496 | }, 497 | { 498 | "cell_type": "code", 499 | "execution_count": null, 500 | "metadata": {}, 501 | "outputs": [], 502 | "source": [ 503 | "# identity operator\n", 504 | "is\n", 505 | "not is" 506 | ] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "execution_count": null, 511 | "metadata": {}, 512 | "outputs": [], 513 | "source": [ 514 | "# Bitwise Operator\n", 515 | "& - bitwise and \n", 516 | "| - bitwise or\n", 517 | "^ - bitwise xor\n", 518 | "<< bitwise left shift\n", 519 | ">> bitwise right shift" 520 | ] 521 | }, 522 | { 523 | "cell_type": "code", 524 | "execution_count": null, 525 | "metadata": {}, 526 | "outputs": [], 527 | "source": [ 528 | "bit\n", 529 | "number\n", 530 | "characters\n", 531 | "instruction\n", 532 | "program\n", 533 | "software" 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": null, 539 | "metadata": {}, 540 | "outputs": [], 541 | "source": [ 542 | "1 byte - 8 bits\n", 543 | "2 bytes - 16 bits\n", 544 | "1kb - 1024 bytes\n", 545 | "1mb - 1024kb\n", 546 | "1gb - 1024mb\n" 547 | ] 548 | }, 549 | { 550 | "cell_type": "code", 551 | "execution_count": null, 552 | "metadata": {}, 553 | "outputs": [], 554 | "source": [ 555 | " 512 256 128 64 32 16 8 4 2 1\n", 556 | "# 1 0 1 1\n", 557 | "# 1 1 1\n", 558 | "#" 559 | ] 560 | }, 561 | { 562 | "cell_type": "code", 563 | "execution_count": null, 564 | "metadata": {}, 565 | "outputs": [], 566 | "source": [ 567 | "# and \n", 568 | "# truth table\n", 569 | "\n", 570 | "0 & 0 = 0\n", 571 | "0 & 1 = 0\n", 572 | "1 & 0 = 0\n", 573 | "1 & 1 = 1" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": 23, 579 | "metadata": {}, 580 | "outputs": [ 581 | { 582 | "name": "stdout", 583 | "output_type": "stream", 584 | "text": [ 585 | "0\n" 586 | ] 587 | } 588 | ], 589 | "source": [ 590 | "print(8 & 2)\n", 591 | "\n", 592 | "# 1000\n", 593 | "# 0010\n", 594 | "# 0000" 595 | ] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "execution_count": 24, 600 | "metadata": {}, 601 | "outputs": [ 602 | { 603 | "name": "stdout", 604 | "output_type": "stream", 605 | "text": [ 606 | "0\n" 607 | ] 608 | } 609 | ], 610 | "source": [ 611 | "print(11 & 4)\n", 612 | "\n", 613 | "# 1011\n", 614 | "# 0100\n", 615 | "# 0000" 616 | ] 617 | }, 618 | { 619 | "cell_type": "code", 620 | "execution_count": null, 621 | "metadata": {}, 622 | "outputs": [], 623 | "source": [ 624 | "111 - 7" 625 | ] 626 | } 627 | ], 628 | "metadata": { 629 | "kernelspec": { 630 | "display_name": "Python 3", 631 | "language": "python", 632 | "name": "python3" 633 | }, 634 | "language_info": { 635 | "codemirror_mode": { 636 | "name": "ipython", 637 | "version": 3 638 | }, 639 | "file_extension": ".py", 640 | "mimetype": "text/x-python", 641 | "name": "python", 642 | "nbconvert_exporter": "python", 643 | "pygments_lexer": "ipython3", 644 | "version": "3.7.6" 645 | } 646 | }, 647 | "nbformat": 4, 648 | "nbformat_minor": 4 649 | } 650 | -------------------------------------------------------------------------------- /30_Exception Handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Exception Handling\n", 8 | "Common Exceptions\n", 9 | "\n", 10 | "Exception Handling\n", 11 | "\n", 12 | "Try\n", 13 | "\n", 14 | "Except\n", 15 | "\n", 16 | "Try except else\n", 17 | "\n", 18 | "Finally\n", 19 | "\n", 20 | "Raising exceptions\n", 21 | "\n", 22 | "Assertion" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "# Exception\n", 30 | "\n", 31 | "runtime errors" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "ename": "ZeroDivisionError", 41 | "evalue": "division by zero", 42 | "output_type": "error", 43 | "traceback": [ 44 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 45 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 46 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 47 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "a = 0\n", 53 | "b = 1\n", 54 | "\n", 55 | "print(b/a)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "ename": "TypeError", 65 | "evalue": "can only concatenate str (not \"int\") to str", 66 | "output_type": "error", 67 | "traceback": [ 68 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 69 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 70 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"A\"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 71 | "\u001b[0;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 72 | ] 73 | } 74 | ], 75 | "source": [ 76 | "print(\"A\" + 10)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "ename": "NameError", 86 | "evalue": "name 'y' is not defined", 87 | "output_type": "error", 88 | "traceback": [ 89 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 90 | "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 91 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 92 | "\u001b[0;31mNameError\u001b[0m: name 'y' is not defined" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "print(y)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### common exceptions\n", 105 | "\n", 106 | "ImportError\n", 107 | "\n", 108 | "IndexError\n", 109 | "\n", 110 | "NameError\n", 111 | "\n", 112 | "SyntaxError\n", 113 | "\n", 114 | "TypeError\n", 115 | "\n", 116 | "ValueError" 117 | ] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "# Exception Handling\n", 124 | "\n", 125 | "try - a block that might contains exceptions\n", 126 | "\n", 127 | "except - contains the exception msg / handling code" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 4, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "name": "stdout", 137 | "output_type": "stream", 138 | "text": [ 139 | "An Error Occured\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "try:\n", 145 | " a = 7\n", 146 | " b = 0\n", 147 | " print(a/b)\n", 148 | " print(\"Finish\")\n", 149 | "except ZeroDivisionError:\n", 150 | " print(\"An Error Occured\")" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 6, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "Help on class ZeroDivisionError in module builtins:\n", 163 | "\n", 164 | "class ZeroDivisionError(ArithmeticError)\n", 165 | " | Second argument to a division or modulo operation was zero.\n", 166 | " | \n", 167 | " | Method resolution order:\n", 168 | " | ZeroDivisionError\n", 169 | " | ArithmeticError\n", 170 | " | Exception\n", 171 | " | BaseException\n", 172 | " | object\n", 173 | " | \n", 174 | " | Methods defined here:\n", 175 | " | \n", 176 | " | __init__(self, /, *args, **kwargs)\n", 177 | " | Initialize self. See help(type(self)) for accurate signature.\n", 178 | " | \n", 179 | " | ----------------------------------------------------------------------\n", 180 | " | Static methods defined here:\n", 181 | " | \n", 182 | " | __new__(*args, **kwargs) from builtins.type\n", 183 | " | Create and return a new object. See help(type) for accurate signature.\n", 184 | " | \n", 185 | " | ----------------------------------------------------------------------\n", 186 | " | Methods inherited from BaseException:\n", 187 | " | \n", 188 | " | __delattr__(self, name, /)\n", 189 | " | Implement delattr(self, name).\n", 190 | " | \n", 191 | " | __getattribute__(self, name, /)\n", 192 | " | Return getattr(self, name).\n", 193 | " | \n", 194 | " | __reduce__(...)\n", 195 | " | Helper for pickle.\n", 196 | " | \n", 197 | " | __repr__(self, /)\n", 198 | " | Return repr(self).\n", 199 | " | \n", 200 | " | __setattr__(self, name, value, /)\n", 201 | " | Implement setattr(self, name, value).\n", 202 | " | \n", 203 | " | __setstate__(...)\n", 204 | " | \n", 205 | " | __str__(self, /)\n", 206 | " | Return str(self).\n", 207 | " | \n", 208 | " | with_traceback(...)\n", 209 | " | Exception.with_traceback(tb) --\n", 210 | " | set self.__traceback__ to tb and return self.\n", 211 | " | \n", 212 | " | ----------------------------------------------------------------------\n", 213 | " | Data descriptors inherited from BaseException:\n", 214 | " | \n", 215 | " | __cause__\n", 216 | " | exception cause\n", 217 | " | \n", 218 | " | __context__\n", 219 | " | exception context\n", 220 | " | \n", 221 | " | __dict__\n", 222 | " | \n", 223 | " | __suppress_context__\n", 224 | " | \n", 225 | " | __traceback__\n", 226 | " | \n", 227 | " | args\n", 228 | "\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "help(ZeroDivisionError)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 7, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "Error Occured\n" 246 | ] 247 | } 248 | ], 249 | "source": [ 250 | "try:\n", 251 | " a = 10\n", 252 | " print(\"Hi\" + a)\n", 253 | " print(a/2)\n", 254 | "except ZeroDivisionError:\n", 255 | " print(\"Do not Divide by Zero\")\n", 256 | "except (ValueError, TypeError):\n", 257 | " print(\"Error Occured\")" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 8, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "Something went wrong!\n" 270 | ] 271 | } 272 | ], 273 | "source": [ 274 | "try:\n", 275 | " w = \"String\"\n", 276 | " print(w/0)\n", 277 | "except:\n", 278 | " print(\"Something went wrong!\")" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": null, 284 | "metadata": {}, 285 | "outputs": [], 286 | "source": [] 287 | } 288 | ], 289 | "metadata": { 290 | "kernelspec": { 291 | "display_name": "Python 3", 292 | "language": "python", 293 | "name": "python3" 294 | }, 295 | "language_info": { 296 | "codemirror_mode": { 297 | "name": "ipython", 298 | "version": 3 299 | }, 300 | "file_extension": ".py", 301 | "mimetype": "text/x-python", 302 | "name": "python", 303 | "nbconvert_exporter": "python", 304 | "pygments_lexer": "ipython3", 305 | "version": "3.7.6" 306 | } 307 | }, 308 | "nbformat": 4, 309 | "nbformat_minor": 4 310 | } 311 | -------------------------------------------------------------------------------- /34_Packages/__pycache__/index.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/34_Packages/__pycache__/index.cpython-37.pyc -------------------------------------------------------------------------------- /34_Packages/app.py: -------------------------------------------------------------------------------- 1 | # import index 2 | 3 | # index.hello() 4 | 5 | # import index as i 6 | 7 | # i.hello() 8 | # i.bye() 9 | 10 | from mypackage import indore, goa 11 | 12 | indore.hello() 13 | 14 | goa.rave() -------------------------------------------------------------------------------- /34_Packages/index.py: -------------------------------------------------------------------------------- 1 | def hello(): 2 | print("Hello from index module") 3 | 4 | def bye(): 5 | print("Bye from index module") -------------------------------------------------------------------------------- /34_Packages/mypackage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/34_Packages/mypackage/__init__.py -------------------------------------------------------------------------------- /34_Packages/mypackage/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/34_Packages/mypackage/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /34_Packages/mypackage/__pycache__/goa.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/34_Packages/mypackage/__pycache__/goa.cpython-37.pyc -------------------------------------------------------------------------------- /34_Packages/mypackage/__pycache__/indore.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/34_Packages/mypackage/__pycache__/indore.cpython-37.pyc -------------------------------------------------------------------------------- /34_Packages/mypackage/goa.py: -------------------------------------------------------------------------------- 1 | def rave(): 2 | print("Rave goa") -------------------------------------------------------------------------------- /34_Packages/mypackage/indore.py: -------------------------------------------------------------------------------- 1 | def hello(): 2 | print("Hello from indore") -------------------------------------------------------------------------------- /35_Python Stack.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Data Structures\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "c\n", 18 | "\n", 19 | "int a = 10;\n", 20 | "# 2 bytes" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "struct cars{\n", 30 | " int customer_id;\n", 31 | " float price;\n", 32 | " char name[10];\n", 33 | "}" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [ 42 | "struct cars c1; # 16 bytes\n", 43 | " int a;" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "c++\n", 53 | "\n", 54 | "class" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "https://github.com/hemansnation/Data-Structures-and-Algorithms" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "# Stack\n", 69 | "\n", 70 | "LIFO (Last In First Out)\n", 71 | "\n", 72 | "### Stack using Python List\n", 73 | "\n", 74 | "push\n", 75 | "\n", 76 | "pop\n", 77 | "\n", 78 | "display" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": null, 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "\n", 88 | "30\n", 89 | "20\n", 90 | "10" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 1, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "[10, 20, 30]\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "stack = []\n", 108 | "\n", 109 | "stack.append(10)\n", 110 | "stack.append(20)\n", 111 | "stack.append(30)\n", 112 | "\n", 113 | "print(stack)\n", 114 | "\n" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 2, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "stack.append(50)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 3, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "[10, 20, 30, 50]" 135 | ] 136 | }, 137 | "execution_count": 3, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "stack" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 4, 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "50\n" 156 | ] 157 | } 158 | ], 159 | "source": [ 160 | "print(stack.pop())" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 5, 166 | "metadata": {}, 167 | "outputs": [ 168 | { 169 | "data": { 170 | "text/plain": [ 171 | "[10, 20, 30]" 172 | ] 173 | }, 174 | "execution_count": 5, 175 | "metadata": {}, 176 | "output_type": "execute_result" 177 | } 178 | ], 179 | "source": [ 180 | "stack" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 6, 186 | "metadata": {}, 187 | "outputs": [ 188 | { 189 | "name": "stdout", 190 | "output_type": "stream", 191 | "text": [ 192 | "30\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "top = stack[-1]\n", 198 | "\n", 199 | "print(top)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "# Stack using Class from scratch" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 18, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "class Stack:\n", 216 | " \n", 217 | " def __init__(self):\n", 218 | " self.data = []\n", 219 | " self.size = 0\n", 220 | " \n", 221 | " def __len__(self):\n", 222 | " return self.size\n", 223 | " \n", 224 | " def is_empty(self):\n", 225 | " return self.size == 0\n", 226 | " \n", 227 | " def push(self, value):\n", 228 | " self.data.append(value)\n", 229 | " self.size += 1\n", 230 | " \n", 231 | " def top(self):\n", 232 | " if self.is_empty():\n", 233 | " return \"Stack is Underflow\"\n", 234 | " return self.data[-1]\n", 235 | " \n", 236 | " def pop(self):\n", 237 | " if self.is_empty():\n", 238 | " return \"Stack is Empty\"\n", 239 | " return self.data.pop()\n", 240 | " \n", 241 | " def display(self):\n", 242 | " return self.data" 243 | ] 244 | }, 245 | { 246 | "cell_type": "code", 247 | "execution_count": 19, 248 | "metadata": {}, 249 | "outputs": [], 250 | "source": [ 251 | "stack = Stack()" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 20, 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "data": { 261 | "text/plain": [ 262 | "__main__.Stack" 263 | ] 264 | }, 265 | "execution_count": 20, 266 | "metadata": {}, 267 | "output_type": "execute_result" 268 | } 269 | ], 270 | "source": [ 271 | "type(stack)" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 21, 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "data": { 281 | "text/plain": [ 282 | "'Stack is Underflow'" 283 | ] 284 | }, 285 | "execution_count": 21, 286 | "metadata": {}, 287 | "output_type": "execute_result" 288 | } 289 | ], 290 | "source": [ 291 | "stack.top()" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 22, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "data": { 301 | "text/plain": [ 302 | "True" 303 | ] 304 | }, 305 | "execution_count": 22, 306 | "metadata": {}, 307 | "output_type": "execute_result" 308 | } 309 | ], 310 | "source": [ 311 | "stack.is_empty()" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 23, 317 | "metadata": {}, 318 | "outputs": [], 319 | "source": [ 320 | "stack.push(10)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 24, 326 | "metadata": {}, 327 | "outputs": [], 328 | "source": [ 329 | "stack.push(11)" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 25, 335 | "metadata": {}, 336 | "outputs": [], 337 | "source": [ 338 | "stack.push(81)\n", 339 | "stack.push(100)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 26, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "[10, 11, 81, 100]" 351 | ] 352 | }, 353 | "execution_count": 26, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "stack.display()" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 27, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "100" 371 | ] 372 | }, 373 | "execution_count": 27, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "stack.top()" 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "execution_count": 28, 385 | "metadata": {}, 386 | "outputs": [ 387 | { 388 | "data": { 389 | "text/plain": [ 390 | "4" 391 | ] 392 | }, 393 | "execution_count": 28, 394 | "metadata": {}, 395 | "output_type": "execute_result" 396 | } 397 | ], 398 | "source": [ 399 | "stack.__len__()" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": null, 405 | "metadata": {}, 406 | "outputs": [], 407 | "source": [] 408 | } 409 | ], 410 | "metadata": { 411 | "kernelspec": { 412 | "display_name": "Python 3", 413 | "language": "python", 414 | "name": "python3" 415 | }, 416 | "language_info": { 417 | "codemirror_mode": { 418 | "name": "ipython", 419 | "version": 3 420 | }, 421 | "file_extension": ".py", 422 | "mimetype": "text/x-python", 423 | "name": "python", 424 | "nbconvert_exporter": "python", 425 | "pygments_lexer": "ipython3", 426 | "version": "3.7.6" 427 | } 428 | }, 429 | "nbformat": 4, 430 | "nbformat_minor": 4 431 | } 432 | -------------------------------------------------------------------------------- /36_Queue and Linear Searching.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Queue\n", 8 | "\n", 9 | "FIFO (First In First Out)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": {}, 16 | "outputs": [], 17 | "source": [ 18 | " None 50 100 70\n", 19 | " rare\n", 20 | " front" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "insert - enqueue\n", 30 | "delete - dequeue\n", 31 | "display\n", 32 | "first" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "data": { 42 | "text/plain": [ 43 | "[5]" 44 | ] 45 | }, 46 | "execution_count": 3, 47 | "metadata": {}, 48 | "output_type": "execute_result" 49 | } 50 | ], 51 | "source": [ 52 | "l = [None]\n", 53 | "\n", 54 | "l[0] = 5\n", 55 | "\n", 56 | "l" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 4, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "data": { 66 | "text/plain": [ 67 | "[None, None, None]" 68 | ] 69 | }, 70 | "execution_count": 4, 71 | "metadata": {}, 72 | "output_type": "execute_result" 73 | } 74 | ], 75 | "source": [ 76 | "[None] * 3" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 20, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "class Queue:\n", 86 | " \n", 87 | " DEFAULT_CAPACITY = 10\n", 88 | " \n", 89 | " def __init__(self):\n", 90 | " self.data = [None] * Queue.DEFAULT_CAPACITY # [None, None, None -----]\n", 91 | " self.size = 0\n", 92 | " self.front = 0\n", 93 | " self.rare = 0\n", 94 | " \n", 95 | " def __len__(self):\n", 96 | " return self.size\n", 97 | " \n", 98 | " def is_empty(self):\n", 99 | " return self.size == 0\n", 100 | " \n", 101 | " def first(self):\n", 102 | " if self.is_empty():\n", 103 | " return \"Queue is Empty\"\n", 104 | " return self.data[self.front]\n", 105 | " \n", 106 | " # dequeue - delete an element\n", 107 | " def dequeue(self):\n", 108 | " if self.is_empty():\n", 109 | " return \"Queue is Empty\"\n", 110 | " answer = self.data[self.rare]\n", 111 | " self.data[self.rare] = None\n", 112 | " \n", 113 | " self.rare += 1\n", 114 | " self.size -= 1\n", 115 | " \n", 116 | " return answer \n", 117 | " \n", 118 | " # enqueue - insert an element\n", 119 | " def enqueue(self, element):\n", 120 | " if self.size == Queue.DEFAULT_CAPACITY:\n", 121 | " return \"Queue is Overflow\"\n", 122 | " \n", 123 | " a = self.front + 1\n", 124 | " self.data[a] = element\n", 125 | " \n", 126 | " self.front += 1\n", 127 | " self.size += 1\n", 128 | " \n", 129 | " def display(self):\n", 130 | " if self.is_empty():\n", 131 | " return \"Queue is Empty\"\n", 132 | " i = self.rare\n", 133 | " while(i <= self.front):\n", 134 | " print(self.data[i])\n", 135 | " i += 1\n", 136 | " " 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 21, 142 | "metadata": {}, 143 | "outputs": [], 144 | "source": [ 145 | "q = Queue()" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 22, 151 | "metadata": {}, 152 | "outputs": [ 153 | { 154 | "data": { 155 | "text/plain": [ 156 | "0" 157 | ] 158 | }, 159 | "execution_count": 22, 160 | "metadata": {}, 161 | "output_type": "execute_result" 162 | } 163 | ], 164 | "source": [ 165 | "q.__len__()" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 23, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "True" 177 | ] 178 | }, 179 | "execution_count": 23, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "q.is_empty()" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 24, 191 | "metadata": {}, 192 | "outputs": [], 193 | "source": [ 194 | "q.enqueue(10)\n" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 25, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "10" 206 | ] 207 | }, 208 | "execution_count": 25, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "q.first()" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 26, 220 | "metadata": {}, 221 | "outputs": [], 222 | "source": [ 223 | "q.enqueue(50)\n", 224 | "q.enqueue(100)\n", 225 | "q.enqueue(15)\n" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 27, 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/plain": [ 236 | "15" 237 | ] 238 | }, 239 | "execution_count": 27, 240 | "metadata": {}, 241 | "output_type": "execute_result" 242 | } 243 | ], 244 | "source": [ 245 | "q.first()" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 28, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "4" 257 | ] 258 | }, 259 | "execution_count": 28, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "q.__len__()" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 29, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/plain": [ 276 | "0" 277 | ] 278 | }, 279 | "execution_count": 29, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "q.rare" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 31, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "None\n", 298 | "10\n", 299 | "50\n", 300 | "100\n", 301 | "15\n" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "q.display()" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "metadata": {}, 312 | "source": [ 313 | "# Searching" 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 32, 319 | "metadata": {}, 320 | "outputs": [ 321 | { 322 | "name": "stdout", 323 | "output_type": "stream", 324 | "text": [ 325 | "True\n" 326 | ] 327 | } 328 | ], 329 | "source": [ 330 | "a = [1,2,3,4,5,6,7,8,9,10]\n", 331 | "\n", 332 | "# membership operator\n", 333 | "\n", 334 | "print(2 in a)" 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 33, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "False\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "print(20 in a)" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 34, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "name": "stdout", 361 | "output_type": "stream", 362 | "text": [ 363 | "True\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "print(20 not in a)" 369 | ] 370 | }, 371 | { 372 | "cell_type": "markdown", 373 | "metadata": {}, 374 | "source": [ 375 | "# Linear Search" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 36, 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "name": "stdout", 385 | "output_type": "stream", 386 | "text": [ 387 | "Enter a number100\n", 388 | "Search Fail\n" 389 | ] 390 | } 391 | ], 392 | "source": [ 393 | "l = [11,25,3,41,50,88, 66, 99]\n", 394 | "# n\n", 395 | "\n", 396 | "# n = 88\n", 397 | "n = int(input(\"Enter a number\"))\n", 398 | "\n", 399 | "## flag bit variable\n", 400 | "f = 0\n", 401 | "\n", 402 | "for i in range(len(l)):\n", 403 | " if l[i] == n:\n", 404 | " f = 1\n", 405 | " break\n", 406 | "\n", 407 | "if f == 1:\n", 408 | " print(\"Search Success\")\n", 409 | "else:\n", 410 | " print(\"Search Fail\")" 411 | ] 412 | }, 413 | { 414 | "cell_type": "code", 415 | "execution_count": null, 416 | "metadata": {}, 417 | "outputs": [], 418 | "source": [] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": null, 430 | "metadata": {}, 431 | "outputs": [], 432 | "source": [] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": null, 437 | "metadata": {}, 438 | "outputs": [], 439 | "source": [] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": {}, 445 | "outputs": [], 446 | "source": [] 447 | } 448 | ], 449 | "metadata": { 450 | "kernelspec": { 451 | "display_name": "Python 3", 452 | "language": "python", 453 | "name": "python3" 454 | }, 455 | "language_info": { 456 | "codemirror_mode": { 457 | "name": "ipython", 458 | "version": 3 459 | }, 460 | "file_extension": ".py", 461 | "mimetype": "text/x-python", 462 | "name": "python", 463 | "nbconvert_exporter": "python", 464 | "pygments_lexer": "ipython3", 465 | "version": "3.7.6" 466 | } 467 | }, 468 | "nbformat": 4, 469 | "nbformat_minor": 4 470 | } 471 | -------------------------------------------------------------------------------- /37_Virtual Environment and Scrapping/main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | 4 | url = 'https://archive.ics.uci.edu/ml/datasets.php' 5 | 6 | response = requests.get(url) 7 | 8 | status = response.status_code 9 | 10 | print(status) 11 | 12 | content = response.content 13 | 14 | soup = BeautifulSoup(content, 'html.parser') 15 | 16 | print(soup.title) # UCI Machine Learning Repository: Data Sets 17 | print(soup.title.get_text()) 18 | 19 | # print(soup.body) 20 | 21 | tables = soup.find_all('table', {'cellpadding': '3'}) 22 | 23 | table = tables[0] 24 | 25 | for td in table.find('tr').find_all('td'): 26 | print(td.text) -------------------------------------------------------------------------------- /38_Flask Framework/1_Flask Basics/application.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def index(): 7 | return "Hello from first Flask App" 8 | 9 | @app.route('/home') 10 | def home(): 11 | return "

Hello Home

" 12 | 13 | 14 | @app.route('/profile') 15 | def profile(): 16 | goa = "Hi this is Goa to Indore" 17 | return render_template('index.html', name="hello") 18 | 19 | if __name__ == '__main__': 20 | app.run(port=5002) 21 | 22 | 23 | # localhost - 127.0.0.1:5000 24 | 25 | 26 | # https://github.com/hemansnation/Python-Roadmap-2022 27 | # scheme domain name route 28 | # DNS -------------------------------------------------------------------------------- /38_Flask Framework/1_Flask Basics/static/css/style.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: blueviolet; 3 | } 4 | 5 | h1{ 6 | color: aliceblue; 7 | } -------------------------------------------------------------------------------- /38_Flask Framework/1_Flask Basics/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | My Index Page 4 | 6 | 7 | 8 | 9 | 10 |

This is our first template for Flask

11 | 12 |

13 | {{ name }} 14 |

15 | 16 | 17 | -------------------------------------------------------------------------------- /39_40_Python and MongoDB Database/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | import os 3 | 4 | MONGODB_URI = 'mongodb+srv://himanshu:him12345@python-june.m1kdy6d.mongodb.net/?retryWrites=true&w=majority' 5 | client = pymongo.MongoClient(MONGODB_URI) 6 | 7 | # creating database 8 | db = client.june_python 9 | # creating student collection and document 10 | # db.students.insert_one({ 11 | # 'name':'Anuj', 12 | # 'country': 'India', 13 | # 'city':'Indore', 14 | # 'age': '21' 15 | # }) 16 | 17 | # CRUD - Create Read Update Delete 18 | 19 | # inserting multiple values 20 | 21 | students = [ 22 | {'name': 'Dev', 'country': 'India', 'city': 'Indore', 'age': 34}, 23 | {'name': 'Rohit', 'country': 'India', 'city': 'Indore', 'age': 24}, 24 | {'name': 'Ravi', 'country': 'USA', 'city': 'Boston', 'age': 41}, 25 | ] 26 | 27 | for student in students: 28 | db.students.insert_one(student) 29 | 30 | 31 | # Read - Find 32 | 33 | student = db.students.find_one() 34 | print(student) # { '_id': ObjectId('4545y43jb4892y3324y932') 'name': 'Dev', 'country': 'India', 'city': 'Indore', 'age': 34} 35 | 36 | db = client['june_python'] 37 | 38 | student = db.students.find_one({'_id': ObjectId('4545y43jb4892y3324y932')}) 39 | print(student) 40 | 41 | 42 | # find 43 | 44 | db = client['june_python'] 45 | 46 | students = db.students.find() 47 | for student in students: 48 | print(student) 49 | 50 | # find with query/condition 51 | 52 | 53 | db = client['june_python'] 54 | 55 | # query = { 56 | # 'country': 'USA', 57 | # 'city':'Boston' 58 | # } 59 | query = { 60 | 'age': {'$gt': 25} 61 | } 62 | 63 | students = db.students.find(query) 64 | for student in students: 65 | print(student) 66 | 67 | # limits 68 | 69 | db.students.find().limit(3) # 3 documents/rows 70 | 71 | # sort 72 | db.student.find().sort('name') 73 | 74 | 75 | 76 | # update 77 | 78 | query = {'age': 250} 79 | new_value = {'$set': {'age':30}} 80 | 81 | db.students.update_one(query, new_value) 82 | 83 | for student in db.students.find(): 84 | print(student) 85 | 86 | 87 | 88 | 89 | # delete 90 | 91 | query = { 92 | 'name': 'Dev' 93 | } 94 | 95 | db.students.delete_one(query) 96 | 97 | for student in db.students.find(): 98 | print(student) 99 | 100 | 101 | # drop the collection 102 | 103 | db.students.drop() 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | print(client.list_database_names()) 113 | 114 | app = Flask(__name__) 115 | 116 | if __name__ == '__main__': 117 | port = int(os.environ.get("PORT", 5000)) 118 | app.run(debug=True, host='0.0.0.0', port=port) -------------------------------------------------------------------------------- /4_Conditional Statements.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Conditional Statements\n", 8 | "1. If Else\n", 9 | "2. If\n", 10 | "3. Else\n", 11 | "4. El If (else if)\n", 12 | "5. If Else Ternary Expression" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": {}, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "Hello\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "a = 10\n", 30 | "\n", 31 | "if a > 5:\n", 32 | " print(\"Hello\")" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "a = 10\n", 42 | "\n", 43 | "if a > 15:\n", 44 | " print(\"Hello\")" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 3, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Hello\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "a = 10\n", 62 | "\n", 63 | "if a > 5:\n", 64 | " print(\"Hello\")\n", 65 | "else:\n", 66 | " print(\"Bye\")" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "Bye\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "a = 10\n", 84 | "\n", 85 | "if a > 15:\n", 86 | " print(\"Hello\")\n", 87 | "else:\n", 88 | " print(\"Bye\")" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 5, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "ename": "SyntaxError", 98 | "evalue": "invalid syntax (, line 1)", 99 | "output_type": "error", 100 | "traceback": [ 101 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m else:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "else:\n", 107 | " print(\"Hi\")" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": 8, 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "Indore\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "a = 5\n", 125 | "\n", 126 | "if a == 10:\n", 127 | " print(\"Hello\")\n", 128 | " print(\"Hi\")\n", 129 | "elif a < 6:\n", 130 | " print(\"Indore\")\n", 131 | "elif a == 5:\n", 132 | " print(\"Goa\")\n", 133 | "else:\n", 134 | " print(\"Incorrect\")" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 9, 140 | "metadata": {}, 141 | "outputs": [ 142 | { 143 | "name": "stdout", 144 | "output_type": "stream", 145 | "text": [ 146 | "Indore\n" 147 | ] 148 | } 149 | ], 150 | "source": [ 151 | "a = 5\n", 152 | "\n", 153 | "if a == 10:\n", 154 | " print(\"Hello\")\n", 155 | " print(\"Hi\")\n", 156 | "elif a < 6:\n", 157 | " print(\"Indore\")\n", 158 | "elif a == 5:\n", 159 | " print(\"Goa\")" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": 10, 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "ename": "SyntaxError", 169 | "evalue": "invalid syntax (, line 3)", 170 | "output_type": "error", 171 | "traceback": [ 172 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m elif a < 6:\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 173 | ] 174 | } 175 | ], 176 | "source": [ 177 | "a = 5\n", 178 | "\n", 179 | "elif a < 6:\n", 180 | " print(\"Indore\")\n", 181 | "elif a == 5:\n", 182 | " print(\"Goa\")" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 13, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "1\n", 195 | "3\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "a = 5\n", 201 | "if a == 5:\n", 202 | " print(1)\n", 203 | "if a < 4:\n", 204 | " print(2)\n", 205 | "else:\n", 206 | " print(3)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "### Nested If else" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 14, 219 | "metadata": {}, 220 | "outputs": [ 221 | { 222 | "name": "stdout", 223 | "output_type": "stream", 224 | "text": [ 225 | "1\n", 226 | "3\n", 227 | "4\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "a = 7\n", 233 | "\n", 234 | "if a > 4:\n", 235 | " print(1)\n", 236 | " if a == 5:\n", 237 | " print(2)\n", 238 | " else:\n", 239 | " print(3)\n", 240 | " if a == 7:\n", 241 | " print(4)\n", 242 | "else:\n", 243 | " print(5)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 19, 249 | "metadata": {}, 250 | "outputs": [ 251 | { 252 | "name": "stdout", 253 | "output_type": "stream", 254 | "text": [ 255 | "Enter a number: 1\n", 256 | "8\n" 257 | ] 258 | } 259 | ], 260 | "source": [ 261 | "a = int(input(\"Enter a number: \"))\n", 262 | "\n", 263 | "if a > 4:\n", 264 | " print(1)\n", 265 | " if a == 5:\n", 266 | " print(2)\n", 267 | " if a < 3:\n", 268 | " print(3)\n", 269 | " elif a > 4:\n", 270 | " print(4)\n", 271 | " elif a == 7:\n", 272 | " print(5)\n", 273 | " if a != 7:\n", 274 | " print(6)\n", 275 | " else:\n", 276 | " print(7)\n", 277 | "else:\n", 278 | " if a == 1:\n", 279 | " print(8)\n", 280 | " else:\n", 281 | " print(9)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "markdown", 286 | "metadata": {}, 287 | "source": [ 288 | "### Ternary Statements" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": null, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | " ? : # ternary operator" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 20, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "name": "stdout", 307 | "output_type": "stream", 308 | "text": [ 309 | "5\n" 310 | ] 311 | } 312 | ], 313 | "source": [ 314 | "a = 10\n", 315 | "\n", 316 | "b = 5 if a == 10 else 45\n", 317 | "\n", 318 | "print(b)" 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 21, 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "name": "stdout", 328 | "output_type": "stream", 329 | "text": [ 330 | "45\n" 331 | ] 332 | } 333 | ], 334 | "source": [ 335 | "a = 10\n", 336 | "\n", 337 | "b = 5 if a > 11 else 45\n", 338 | "\n", 339 | "print(b)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 22, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "Login\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "status = 1\n", 357 | "\n", 358 | "msg = \"Login\" if status == 1 else \"Logout\"\n", 359 | "\n", 360 | "print(msg)" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "metadata": {}, 366 | "source": [ 367 | "**WAP to enter a number from user and print its absolute value**" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": null, 373 | "metadata": {}, 374 | "outputs": [], 375 | "source": [ 376 | "-1 => 1\n", 377 | "-3 => 3" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 25, 383 | "metadata": {}, 384 | "outputs": [ 385 | { 386 | "name": "stdout", 387 | "output_type": "stream", 388 | "text": [ 389 | "Enter a Number: 0\n", 390 | "0\n" 391 | ] 392 | } 393 | ], 394 | "source": [ 395 | "n = int(input(\"Enter a Number: \"))\n", 396 | "\n", 397 | "if n < 0:\n", 398 | " print( n * (-1) )\n", 399 | "else:\n", 400 | " print(n)" 401 | ] 402 | }, 403 | { 404 | "cell_type": "markdown", 405 | "metadata": {}, 406 | "source": [ 407 | "**WAP to enter single digit from user and print its character format**" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": null, 413 | "metadata": {}, 414 | "outputs": [], 415 | "source": [ 416 | "5\n", 417 | "Five" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": null, 423 | "metadata": {}, 424 | "outputs": [], 425 | "source": [ 426 | "n = int(input(\"Enter a number\"))\n", 427 | "\n", 428 | "if n == 1:\n", 429 | " print(\"One\")\n", 430 | "elif n == 2:\n", 431 | " print(\"Two\")" 432 | ] 433 | }, 434 | { 435 | "cell_type": "markdown", 436 | "metadata": {}, 437 | "source": [ 438 | "**WAP to enter a character from user and check if it is vowel or consonant**" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": {}, 445 | "outputs": [], 446 | "source": [ 447 | "a\n", 448 | "Vowel" 449 | ] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "execution_count": null, 454 | "metadata": {}, 455 | "outputs": [], 456 | "source": [ 457 | "n = input()\n", 458 | "\n", 459 | "if n == 'a':\n", 460 | " print(\"vowel\")\n", 461 | "elif n == 'e':\n", 462 | " print(\"vowel\")\n", 463 | ".\n", 464 | ".\n", 465 | ".\n", 466 | "else:\n", 467 | " print(\"consonant\")" 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 2, 473 | "metadata": {}, 474 | "outputs": [ 475 | { 476 | "name": "stdout", 477 | "output_type": "stream", 478 | "text": [ 479 | "Enter a characterk\n", 480 | "consonant\n" 481 | ] 482 | } 483 | ], 484 | "source": [ 485 | "n = input(\"Enter a character\")\n", 486 | "\n", 487 | "if n == 'a' or n == 'e' or n == 'i' or n == 'o' or n == 'u':\n", 488 | " print(\"vowel\")\n", 489 | "else:\n", 490 | " print(\"consonant\")" 491 | ] 492 | }, 493 | { 494 | "cell_type": "code", 495 | "execution_count": 4, 496 | "metadata": {}, 497 | "outputs": [ 498 | { 499 | "ename": "SyntaxError", 500 | "evalue": "invalid syntax (, line 3)", 501 | "output_type": "error", 502 | "traceback": [ 503 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m if n == 'a' || n == 'e' || n == 'i' || n == 'o' || n == 'u':\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 504 | ] 505 | } 506 | ], 507 | "source": [ 508 | "n = input(\"Enter a character\")\n", 509 | "\n", 510 | "if n == 'a' | n == 'e' | n == 'i' | n == 'o' | n == 'u':\n", 511 | " print(\"vowel\")\n", 512 | "else:\n", 513 | " print(\"consonant\")" 514 | ] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "execution_count": null, 519 | "metadata": {}, 520 | "outputs": [], 521 | "source": [] 522 | } 523 | ], 524 | "metadata": { 525 | "kernelspec": { 526 | "display_name": "Python 3", 527 | "language": "python", 528 | "name": "python3" 529 | }, 530 | "language_info": { 531 | "codemirror_mode": { 532 | "name": "ipython", 533 | "version": 3 534 | }, 535 | "file_extension": ".py", 536 | "mimetype": "text/x-python", 537 | "name": "python", 538 | "nbconvert_exporter": "python", 539 | "pygments_lexer": "ipython3", 540 | "version": "3.7.6" 541 | } 542 | }, 543 | "nbformat": 4, 544 | "nbformat_minor": 4 545 | } 546 | -------------------------------------------------------------------------------- /5_While Loop.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 4 | While Loop\n", 8 | "1. While loop logic building\n", 9 | "2. Series based Questions\n", 10 | "3. Break\n", 11 | "4. Continue\n", 12 | "5. Nested While Loops\n", 13 | "6. Pattern-Based Questions\n", 14 | "7. pass\n", 15 | "8. Loop else" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": null, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "print(\"Himanshu\")" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 1, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "name": "stdout", 34 | "output_type": "stream", 35 | "text": [ 36 | "Himanshu\n", 37 | "Himanshu\n", 38 | "Himanshu\n", 39 | "Himanshu\n", 40 | "Himanshu\n", 41 | "Himanshu\n", 42 | "Himanshu\n", 43 | "Himanshu\n", 44 | "Himanshu\n", 45 | "Himanshu\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "i = 1\n", 51 | "while i <= 10:\n", 52 | " print(\"Himanshu\")\n", 53 | " i += 1" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": null, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "1\n", 63 | "2\n", 64 | "3\n", 65 | "4\n", 66 | "5\n", 67 | "6\n", 68 | "7\n", 69 | "8\n", 70 | "9\n", 71 | "10" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 2, 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "name": "stdout", 81 | "output_type": "stream", 82 | "text": [ 83 | "1\n", 84 | "2\n", 85 | "3\n", 86 | "4\n", 87 | "5\n", 88 | "6\n", 89 | "7\n", 90 | "8\n", 91 | "9\n", 92 | "10\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "i = 1\n", 98 | "while i <= 10:\n", 99 | " print(i)\n", 100 | " i += 1" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 3, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "Hello\n", 113 | "World\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "print(\"Hello\\nWorld\")" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 4, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Hello\n", 131 | "World\n" 132 | ] 133 | } 134 | ], 135 | "source": [ 136 | "print(\"Hello\")\n", 137 | "print(\"World\")" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 5, 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdout", 147 | "output_type": "stream", 148 | "text": [ 149 | "Hello World\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "print(\"Hello\", end=' ') # \"Hello\" + \" \" = \"Hello \"\n", 155 | "print(\"World\")" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 6, 161 | "metadata": {}, 162 | "outputs": [ 163 | { 164 | "name": "stdout", 165 | "output_type": "stream", 166 | "text": [ 167 | "HelloWorld\n" 168 | ] 169 | } 170 | ], 171 | "source": [ 172 | "print(\"Hello\", end='')\n", 173 | "print(\"World\")" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 7, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "Hello\n", 186 | "World\n" 187 | ] 188 | } 189 | ], 190 | "source": [ 191 | "print(\"Hello\", end='\\n') # \"Hello\" + \"\"\n", 192 | "print(\"World\")" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 8, 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "Hello++>World\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "print(\"Hello\", end='++>') # \"Hello\" + \"++>\" = \"Hello++>\"\n", 210 | "print(\"World\")" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": {}, 217 | "outputs": [], 218 | "source": [ 219 | "1 2 3 4 5 6 7 8 9 10" 220 | ] 221 | }, 222 | { 223 | "cell_type": "code", 224 | "execution_count": 9, 225 | "metadata": {}, 226 | "outputs": [ 227 | { 228 | "name": "stdout", 229 | "output_type": "stream", 230 | "text": [ 231 | "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t" 232 | ] 233 | } 234 | ], 235 | "source": [ 236 | "i = 1\n", 237 | "\n", 238 | "while i <= 10:\n", 239 | " print(i, end=\"\\t\")\n", 240 | " i += 1" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 10, 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "1 2 3 4 5 6 7 8 9 10 " 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "i = 1\n", 258 | "\n", 259 | "while i <= 10:\n", 260 | " print(i, end=\" \")\n", 261 | " i += 1" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 12, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "+" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "print(end = '+')" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 13, 284 | "metadata": {}, 285 | "outputs": [ 286 | { 287 | "name": "stdout", 288 | "output_type": "stream", 289 | "text": [ 290 | "1 2 3\n" 291 | ] 292 | } 293 | ], 294 | "source": [ 295 | "a = 1\n", 296 | "b = 2\n", 297 | "c = 3\n", 298 | "print(a,b,c)" 299 | ] 300 | }, 301 | { 302 | "cell_type": "markdown", 303 | "metadata": {}, 304 | "source": [ 305 | "**WAP to print following series**" 306 | ] 307 | }, 308 | { 309 | "cell_type": "code", 310 | "execution_count": null, 311 | "metadata": {}, 312 | "outputs": [], 313 | "source": [ 314 | "1 4 9 16 25 36 49 64 81 100" 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 14, 320 | "metadata": {}, 321 | "outputs": [ 322 | { 323 | "name": "stdout", 324 | "output_type": "stream", 325 | "text": [ 326 | "1 4 9 16 25 36 49 64 81 100 " 327 | ] 328 | } 329 | ], 330 | "source": [ 331 | "i = 1\n", 332 | "\n", 333 | "while i <= 10:\n", 334 | " print(i*i, end = ' ')\n", 335 | " i += 1" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 15, 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "name": "stdout", 345 | "output_type": "stream", 346 | "text": [ 347 | "1 4 9 16 25 36 49 64 81 100 " 348 | ] 349 | } 350 | ], 351 | "source": [ 352 | "i = 1\n", 353 | "\n", 354 | "while i <= 10:\n", 355 | " print(i**2, end = ' ')\n", 356 | " i += 1" 357 | ] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "execution_count": null, 362 | "metadata": {}, 363 | "outputs": [], 364 | "source": [ 365 | "1/1 2/4 3/9 4/16 5/25 6/36 7/49 8/64 9/81 10/100" 366 | ] 367 | }, 368 | { 369 | "cell_type": "code", 370 | "execution_count": 16, 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "1 / 1 2 / 4 3 / 9 4 / 16 5 / 25 6 / 36 7 / 49 8 / 64 9 / 81 10 / 100 " 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "i = 1\n", 383 | "\n", 384 | "while i <= 10:\n", 385 | " print(i, '/', i*i, end = ' ')\n", 386 | " i += 1" 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "execution_count": 17, 392 | "metadata": {}, 393 | "outputs": [ 394 | { 395 | "name": "stdout", 396 | "output_type": "stream", 397 | "text": [ 398 | "1/1 2/4 3/9 4/16 5/25 6/36 7/49 8/64 9/81 10/100 " 399 | ] 400 | } 401 | ], 402 | "source": [ 403 | "i = 1\n", 404 | "\n", 405 | "while i <= 10:\n", 406 | " print(i, end='/')\n", 407 | " print(i*i, end=' ')\n", 408 | " i += 1" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [ 417 | "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": 18, 423 | "metadata": {}, 424 | "outputs": [ 425 | { 426 | "name": "stdout", 427 | "output_type": "stream", 428 | "text": [ 429 | "1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + " 430 | ] 431 | } 432 | ], 433 | "source": [ 434 | "i = 1\n", 435 | "\n", 436 | "while i <= 10:\n", 437 | " print(i, end = ' + ')\n", 438 | " i += 1" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": null, 444 | "metadata": {}, 445 | "outputs": [], 446 | "source": [] 447 | } 448 | ], 449 | "metadata": { 450 | "kernelspec": { 451 | "display_name": "Python 3", 452 | "language": "python", 453 | "name": "python3" 454 | }, 455 | "language_info": { 456 | "codemirror_mode": { 457 | "name": "ipython", 458 | "version": 3 459 | }, 460 | "file_extension": ".py", 461 | "mimetype": "text/x-python", 462 | "name": "python", 463 | "nbconvert_exporter": "python", 464 | "pygments_lexer": "ipython3", 465 | "version": "3.7.6" 466 | } 467 | }, 468 | "nbformat": 4, 469 | "nbformat_minor": 4 470 | } 471 | -------------------------------------------------------------------------------- /Python Roadmap 2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/Python Roadmap 2022.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Roadmap 2 | 3 | ![Python Core Header](https://github.com/hemansnation/Python-Roadmap-2022/blob/main/images/pythoncoreheader.png) 4 | 5 | ### The Roadmap is divided into 30 Sections 6 | 7 | 1. Introduction and Basics of Python 8 | 2. Operators 9 | 3. Conditional Statements 10 | 4. While Loops 11 | 5. Lists 12 | 6. Strings 13 | 7. For Loop 14 | 8. Functions 15 | 9. Dictionary 16 | 10. Tuples 17 | 11. Set 18 | 12. Object-Oriented Programming 19 | 13. File Handling 20 | 14. Exception Handling 21 | 15. Regular Expression 22 | 16. Modules and Packages 23 | 17. Data Structures 24 | 18. Higher-Order Functions 25 | 19. Python Web Scrapping 26 | 20. Virtual Environment 27 | 21. Web Application Project 28 | 22. Git and GitHub 29 | 23. Deployment 30 | 24. Python Package Manager 31 | 25. Python with MongoDB Database 32 | 26. Building API 33 | 27. Statistics with NumPy 34 | 28. Data Analysis with Pandas 35 | 29. Data Visualization with Matplotlib 36 | 30. What to do Now? 37 | 38 | 39 | ## 1 | Introduction and Basics 40 | - Installation 41 | - Python Org, Python 3 42 | - Variables 43 | - Print function 44 | - Input from user 45 | - Data Types 46 | - Type Conversion 47 | - First Program 48 | 49 | ## 2 | Operators 50 | - Arithmetic Operators 51 | - Relational Operators 52 | - Bitwise Operators 53 | - Logical Operators 54 | - Assignment Operators 55 | - Compound Operators 56 | - Membership Operators 57 | - Identity Operators 58 | 59 | 60 | ## 3 | Conditional Statements 61 | - If Else 62 | - If 63 | - Else 64 | - El If (else if) 65 | - If Else Ternary Expression 66 | 67 | ## 4 | While Loop 68 | - While loop logic building 69 | - Series based Questions 70 | - Break 71 | - Continue 72 | - Nested While Loops 73 | - Pattern-Based Questions 74 | - pass 75 | - Loop else 76 | 77 | ## 5 | Lists 78 | - List Basics 79 | - List Operations 80 | - List Comprehensions / Slicing 81 | - List Methods 82 | 83 | ## 6 | Strings 84 | - String Basics 85 | - String Literals 86 | - String Operations 87 | - String Comprehensions / Slicing 88 | - String Methods 89 | 90 | ## 7 | For Loops 91 | - Range function 92 | - For loop 93 | - Nested For Loops 94 | - Pattern-Based Questions 95 | - Break 96 | - Continue 97 | - Pass 98 | - Loop else 99 | 100 | ## 8 | Functions 101 | - Definition 102 | - Call 103 | - Function Arguments 104 | - Default Arguments 105 | - Docstrings 106 | - Scope 107 | - Special functions Lambda, Map, and Filter 108 | - Recursion 109 | - Functional Programming and Reference Functions 110 | 111 | 112 | ## 9 | Dictionary 113 | - Dictionaries Basics 114 | - Operations 115 | - Comprehensions 116 | - Dictionaries Methods 117 | 118 | ## 10 | Tuple 119 | - Tuples Basics 120 | - Tuples Comprehensions / Slicing 121 | - Tuple Functions 122 | - Tuple Methods 123 | 124 | ## 11 | Set 125 | - Sets Basics 126 | - Sets Operations 127 | - Union 128 | - Intersection 129 | - Difference and Symmetric Difference 130 | 131 | 132 | 133 | ## 12 | Object-Oriented Programming 134 | - Classes 135 | - Objects 136 | - Method Calls 137 | - Inheritance and Its Types 138 | - Overloading 139 | - Overriding 140 | - Data Hiding 141 | - Operator Overloading 142 | 143 | ## 13 | File Handling 144 | - File Basics 145 | - Opening Files 146 | - Reading Files 147 | - Writing Files 148 | - Editing Files 149 | - Working with different extensions of file 150 | - With Statements 151 | 152 | 153 | ## 14 | Exception Handling 154 | - Common Exceptions 155 | - Exception Handling 156 | - Try 157 | - Except 158 | - Try except else 159 | - Finally 160 | - Raising exceptions 161 | - Assertion 162 | 163 | ## 15 | Regular Expression 164 | - Basic RE functions 165 | - Patterns 166 | - Meta Characters 167 | - Character Classes 168 | 169 | ## 16 | Modules & Packages 170 | - Different types of modules 171 | - Inbuilt modules 172 | - OS 173 | - Sys 174 | - Statistics 175 | - Math 176 | - String 177 | - Random 178 | - Create your own module 179 | - Building Packages 180 | - Build your own python module and deploy it on pip 181 | 182 | 183 | ## 17 | Data Structures 184 | - Stack 185 | - Queue 186 | - Linked Lists 187 | - Sorting 188 | - Searching 189 | - Linear Search 190 | - Binary Search 191 | 192 | ## 18 | Higher-Order Functions 193 | - Function as a parameter 194 | - Function as a return value 195 | - Closures 196 | - Decorators 197 | - Map, Filter, Reduce Functions 198 | 199 | ## 19 | Python Web Scrapping 200 | - Understanding BeautifulSoup 201 | - Extracting Data from websites 202 | - Extracting Tables 203 | - Data in JSON format 204 | 205 | 206 | ## 20 | Virtual Environment 207 | - Virtual Environment Setup 208 | 209 | 210 | ## 21 | Web Application Project 211 | - Flask 212 | - Project Structure 213 | - Routes 214 | - Templates 215 | - Navigations 216 | 217 | 218 | ## 22 | Git and GitHub 219 | - Git - Version Control System 220 | - GitHub Profile building 221 | - Manage your work on GitHub 222 | 223 | 224 | ## 23 | Deployment 225 | - Heroku Deployment 226 | - Flask Integration 227 | 228 | 229 | 230 | ## 24 | Python Package Manager 231 | - What is PIP? 232 | - Installation 233 | - PIP Freeze 234 | - Creating Your Own Package 235 | - Upload it on PIP 236 | 237 | ## 25 | Python with MongoDB Database 238 | - SQL and NoSQL 239 | - Connecting to MongoDB URI 240 | - Flask application and MongoDB integration 241 | - CRUD Operations 242 | - Find 243 | - Delete 244 | - Drop 245 | 246 | ## 26 | Building API 247 | - API (Application Programming Interface) 248 | - Building API 249 | - Structure of an API 250 | - PUT 251 | - POST 252 | - DELETE 253 | - Using Postman 254 | 255 | 256 | ## 27 | Statistics with NumPy 257 | - Statistics 258 | - NumPy basics 259 | - Working with Matrix 260 | - Linear Algebra operations 261 | - Descriptive Statistics 262 | 263 | ## 28 | Data Analysis with Pandas 264 | - Data Analysis basics 265 | - Dataframe operations 266 | - Working with 2-dimensional data 267 | - Data Cleaning 268 | - Data Grouping 269 | 270 | 271 | ## 29 | Data Visualization with Matplotlib 272 | - Matplotlib Basics 273 | - Working with plots 274 | - Plot 275 | - Pie Chart 276 | - Histogram 277 | 278 | 279 | ## 30 | What to do Now? 280 | - Discussions on how to process further with this knowledge. 281 | 282 | 283 | 284 | 285 | ## Join the Python Core 2022 WhatsApp Group here: 286 | 287 | https://chat.whatsapp.com/Fay4UDQo9ZcA2XpMK6biSF 288 | 289 | 290 | 291 | ## Connect with me on these platforms: 292 | 293 | GitHub: https://github.com/hemansnation 294 | 295 | Twitter: https://twitter.com/hemansnation 296 | 297 | LinkedIn: https://www.linkedin.com/in/hemansnation/ 298 | 299 | Instagram: https://www.instagram.com/masterdexter.ai/ 300 | -------------------------------------------------------------------------------- /goa.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/goa.xlsx -------------------------------------------------------------------------------- /hello.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | 3 | print("Hello") 4 | 5 | print(a) -------------------------------------------------------------------------------- /images/pythoncoreheader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/images/pythoncoreheader.png -------------------------------------------------------------------------------- /indore_weather.csv: -------------------------------------------------------------------------------- 1 | ,day,temprature,windspeed,event 2 | 0,1/1/2022,32,6,Rain 3 | 1,1/2/2022,35,7,Sunny 4 | 2,1/3/2022,28,2,Snow 5 | 3,1/4/2022,24,4,Rain 6 | 4,1/5/2022,32,2,Sunny 7 | 5,1/6/2022,31,7,Snow 8 | -------------------------------------------------------------------------------- /mumbai.txt: -------------------------------------------------------------------------------- 1 | This is a virus. -------------------------------------------------------------------------------- /nyc_weather.csv: -------------------------------------------------------------------------------- 1 | EST,Temperature,DewPoint,Humidity,Sea Level PressureIn,VisibilityMiles,WindSpeedMPH,PrecipitationIn,CloudCover,Events,WindDirDegrees 2 | 1/1/2016,38,23,52,30.03,10,8,0,5,,281 3 | 1/2/2016,36,18,46,30.02,10,7,0,3,,275 4 | 1/3/2016,40,21,47,29.86,10,8,0,1,,277 5 | 1/4/2016,25,9,44,30.05,10,9,0,3,,345 6 | 1/5/2016,20,-3,41,30.57,10,5,0,0,,333 7 | 1/6/2016,33,4,35,30.5,10,4,0,0,,259 8 | 1/7/2016,39,11,33,30.28,10,2,0,3,,293 9 | 1/8/2016,39,29,64,30.2,10,4,0,8,,79 10 | 1/9/2016,44,38,77,30.16,9,8,T,8,Rain,76 11 | 1/10/2016,50,46,71,29.59,4,,1.8,7,Rain,109 12 | 1/11/2016,33,8,37,29.92,10,,0,1,,289 13 | 1/12/2016,35,15,53,29.85,10,6,T,4,,235 14 | 1/13/2016,26,4,42,29.94,10,10,0,0,,284 15 | 1/14/2016,30,12,47,29.95,10,5,T,7,,266 16 | 1/15/2016,43,31,62,29.82,9,5,T,2,,101 17 | 1/16/2016,47,37,70,29.52,8,7,0.24,7,Rain,340 18 | 1/17/2016,36,23,66,29.78,8,6,0.05,6,Fog-Snow,345 19 | 1/18/2016,25,6,53,29.83,9,12,T,2,Snow,293 20 | 1/19/2016,22,3,42,30.03,10,11,0,1,,293 21 | 1/20/2016,32,15,49,30.13,10,6,0,2,,302 22 | 1/21/2016,31,11,45,30.15,10,6,0,1,,312 23 | 1/22/2016,26,6,41,30.21,9,,0.01,3,Snow,34 24 | 1/23/2016,26,21,78,29.77,1,16,2.31,8,Fog-Snow,42 25 | 1/24/2016,28,11,53,29.92,8,6,T,3,Snow,327 26 | 1/25/2016,34,18,54,30.25,10,3,0,2,,286 27 | 1/26/2016,43,29,56,30.03,10,7,0,2,,244 28 | 1/27/2016,41,22,45,30.03,10,7,T,3,Rain,311 29 | 1/28/2016,37,20,51,29.9,10,5,0,1,,234 30 | 1/29/2016,36,21,50,29.58,10,8,0,4,,298 31 | 1/30/2016,34,16,46,30.01,10,7,0,0,,257 32 | 1/31/2016,46,28,52,29.9,10,5,0,0,,241 33 | -------------------------------------------------------------------------------- /queens.txt: -------------------------------------------------------------------------------- 1 | spiderman is the new ironman 2 | This is a virus. -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print("Welcome {}, Your city {} your country {}".format(sys.argv[1], sys.argv[2], sys.argv[3])) -------------------------------------------------------------------------------- /student.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemansnation/Python-Roadmap/b8d5c8e4249db87bd10cbfbae5beabb5dd988e54/student.txt --------------------------------------------------------------------------------