├── 01-07-2020(Day-9).ipynb ├── 01-07-2020(Day-9) ├── Modules_Packages.ipynb ├── module.py └── package │ └── mobile.py ├── 02-07-2020 └── 02-07-2020.ipynb ├── 03-07-2020(Day-11).ipynb ├── 04-07-2020(Day-12) ├── File_handling.ipynb ├── book.txt ├── img.jpg ├── mail.txt └── phone.txt ├── 06-07-2020(Day-13).ipynb ├── 06-07-2020 └── 06-07-2020.ipynb ├── 07-07-2020(Day-15) ├── Pandas_7July2020.ipynb ├── birds.csv └── data_Concat.csv ├── 08-07-2020(Day-16) ├── Matplotlib.ipynb └── logo.png ├── 09-07-2020(Day-17) ├── Oops_basics.ipynb └── download.png ├── 10-07-2020(Day-18) ├── OOPS_Inheritance.ipynb ├── inheritence.jpg ├── multi.png ├── multilevel.jpg └── single.png ├── 10-7-2020(matplotlib)aftrnun.ipynb ├── 1st July 2020.ipynb ├── 22-06-2020(Day-1).ipynb ├── 22-06-2020 └── 22-06-2020(Day-1).ipynb ├── 23-06-2020(Day-2).ipynb ├── 24-06-2020(Day-3).ipynb ├── 24-06-2020.ipynb ├── 24th june.ipynb ├── 25-06-2020(Day-4).ipynb ├── 26-06-2020(Day-5).ipynb ├── 27-06-2020(DAY-6).ipynb ├── 29-06-2020 └── 29-06-2020.ipynb ├── 2nd July 2020.ipynb ├── 30-06-2020(Day-8).ipynb ├── 6th July 2020.ipynb ├── 9th July 2020.ipynb ├── Datafiles ├── data.txt ├── data1.txt ├── demo.txt ├── demo1.txt ├── info.txt ├── marks.txt └── task.txt ├── July 10th 2020(Pandas cont..).ipynb ├── June 4,2020(afternun).ipynb ├── Python-Programming-Content.md ├── Resources.md ├── data.csv ├── june27,2020 (DAY-6)aftrnun.ipynb ├── june3,2020(aftrnun) .ipynb └── package └── mobile.py /01-07-2020(Day-9)/module.py: -------------------------------------------------------------------------------- 1 | def isleap(year): 2 | if year%400 == 0 or (year%4 == 0 and year%100 != 0): 3 | return True 4 | return False 5 | 6 | 7 | def hello(name): 8 | return "Hello "+name+" How do you do.. !" -------------------------------------------------------------------------------- /01-07-2020(Day-9)/package/mobile.py: -------------------------------------------------------------------------------- 1 | def vivo(): 2 | print("Features :") 3 | print("Battery : 5000mhg \n RAM : 6GB \n cost : 12000rs ") 4 | 5 | def realme(): 6 | print("Features :") 7 | print("Battery : 5500mhg \n RAM : 32GB \n cost : 10000rs ") -------------------------------------------------------------------------------- /02-07-2020/02-07-2020.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Comprehensions:\n" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "* Comprehension is nothing but Inclusive(within itself).\n", 15 | "* In python we use these comprehensions for simplying for code and reducing the programming lines.
\n", 16 | "\n", 17 | "#### Types of comprehensions:\n", 18 | "\n", 19 | "* List Comprehension\n", 20 | "* Dictionary Comprehension\n", 21 | "* Set Comprehension\n", 22 | "* Generator Comprehension.\n" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "#### List Comprehension:\n", 30 | "\n", 31 | "If we write our code within a list to create the output in the format of list,then that is named as List comprehension.\n" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "name": "stdout", 41 | "output_type": "stream", 42 | "text": [ 43 | "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "### Display the numbers from 1 to 10 in list format.\n", 49 | "\n", 50 | "l = []\n", 51 | "for i in range(1,11):\n", 52 | " l.append(i)\n", 53 | "print(l)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 2, 59 | "metadata": {}, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "List comprehension [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "### List comprehension:\n", 71 | "## first at the starting of list output variable should be defined.\n", 72 | "### Loop should be defined after the output variable\n", 73 | "### conditions sholud be defined after loop.\n", 74 | "\n", 75 | "l = [i for i in range(1,11)]\n", 76 | "print(\"List comprehension\",l)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 3, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "[12, 14, 10, 6]\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "### Print even numbers from a given list in list format:\n", 94 | "\n", 95 | "li = [12,14,3,1,7,10,6]\n", 96 | "l = []\n", 97 | "for i in li:\n", 98 | " if i%2 == 0:\n", 99 | " l.append(i)\n", 100 | "print(l)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 4, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "[12, 14, 10, 6]\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "### list comprehension:\n", 118 | "\n", 119 | "l = [i for i in li if i%2 == 0]\n", 120 | "print(l)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 7, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "[12, 14, 'Odd', 'Odd', 'Odd', 10, 6]\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "#### Print the even numbers in a list and in place of odd numbers replace it with \"odd\"\n", 138 | "\n", 139 | "li = [12,14,3,1,7,10,6]\n", 140 | "l = []\n", 141 | "for i in li:\n", 142 | " if i%2 == 0:\n", 143 | " l.append(i)\n", 144 | " else:\n", 145 | " l.append(\"Odd\")\n", 146 | "print(l)" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 8, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "[12, 14, 'Odd', 'Odd', 'Odd', 10, 6]\n" 159 | ] 160 | } 161 | ], 162 | "source": [ 163 | "###List comprehension:\n", 164 | "### If we use if and else condition at a time ,then condition should be defined \n", 165 | "## first later loop should be defined.\n", 166 | "\n", 167 | "l =[i if i % 2 == 0 else \"Odd\" for i in li]\n", 168 | "print(l)" 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "execution_count": 11, 174 | "metadata": {}, 175 | "outputs": [ 176 | { 177 | "name": "stdout", 178 | "output_type": "stream", 179 | "text": [ 180 | "['python', 'programming', 'summer', 'online', 'training']\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "### task\n", 186 | "### a = [\"python programming\",\"summer online training\"]\n", 187 | "### separate each word with comma and print the output in list format.\n", 188 | "\n", 189 | "a = [\"python programming\",\"summer online training\"]\n", 190 | "li = []\n", 191 | "for i in a :\n", 192 | " for j in i.split():\n", 193 | " li.append(j)\n", 194 | "print(li)\n", 195 | " \n", 196 | " " 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 12, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "['python', 'programming', 'summer', 'online', 'training']\n" 209 | ] 210 | } 211 | ], 212 | "source": [ 213 | "### list comprehension:\n", 214 | "\n", 215 | "a = [\"python programming\",\"summer online training\"]\n", 216 | "\n", 217 | "list_sep = [j for i in a for j in i.split()]\n", 218 | "print(list_sep)" 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "### Dictionary Comprehension:\n", 226 | "\n", 227 | "If we use our code in a Dictionary and the output is printed in the format of dictonary then that will be Dictionary comprehension.\n" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 13, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "name": "stdout", 237 | "output_type": "stream", 238 | "text": [ 239 | "{'Andhra': 'Amaravathi', 'Telangana': 'Hyderabad', 'TamilNadu': 'Chennai'}\n" 240 | ] 241 | } 242 | ], 243 | "source": [ 244 | "state = [\"Andhra\",\"Telangana\",\"TamilNadu\"]\n", 245 | "capital = [\"Amaravathi\",\"Hyderabad\",\"Chennai\"]\n", 246 | "\n", 247 | "c = {}\n", 248 | "for (key,value) in zip(state,capital):\n", 249 | " c[key] = value\n", 250 | "print(c)" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 14, 256 | "metadata": {}, 257 | "outputs": [ 258 | { 259 | "name": "stdout", 260 | "output_type": "stream", 261 | "text": [ 262 | "{'Andhra': 'Amaravathi', 'Telangana': 'Hyderabad', 'TamilNadu': 'Chennai'}\n" 263 | ] 264 | } 265 | ], 266 | "source": [ 267 | "### Dictionary Comprehension:\n", 268 | "\n", 269 | "output = {key:value for (key,value) in zip(state,capital)}\n", 270 | "print(output)" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": 17, 276 | "metadata": {}, 277 | "outputs": [ 278 | { 279 | "name": "stdout", 280 | "output_type": "stream", 281 | "text": [ 282 | "{1: 1, 2: 4, 6: 36, 9: 81, 10: 100}\n" 283 | ] 284 | } 285 | ], 286 | "source": [ 287 | "#### li = [1,2,6,9,10]\n", 288 | "### d = {1:1,2:4,6:36,9:81,10:100}\n", 289 | "li = [1,2,6,9,10]\n", 290 | "d ={i:i**2 for i in li}\n", 291 | "print(d)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "markdown", 296 | "metadata": {}, 297 | "source": [ 298 | "### Set Comprehension:\n", 299 | "\n", 300 | "* Set comprehension is also as same as list comprehension but the main difference is set accepts unique elements.\n" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 18, 306 | "metadata": {}, 307 | "outputs": [ 308 | { 309 | "name": "stdout", 310 | "output_type": "stream", 311 | "text": [ 312 | "{89, 1, 3, 5}\n" 313 | ] 314 | } 315 | ], 316 | "source": [ 317 | "li =[1,2,3,3,6,89,5,5]\n", 318 | "s = set()\n", 319 | "for i in li:\n", 320 | " if i % 2 !=0:\n", 321 | " s.add(i)\n", 322 | "print(s)" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 19, 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "name": "stdout", 332 | "output_type": "stream", 333 | "text": [ 334 | "{89, 1, 3, 5}\n" 335 | ] 336 | } 337 | ], 338 | "source": [ 339 | "### Set comprehension:\n", 340 | "\n", 341 | "s = {i for i in li if i%2!=0}\n", 342 | "print(s)" 343 | ] 344 | }, 345 | { 346 | "cell_type": "markdown", 347 | "metadata": {}, 348 | "source": [ 349 | "### Generator Comprehension:\n" 350 | ] 351 | }, 352 | { 353 | "cell_type": "markdown", 354 | "metadata": {}, 355 | "source": [ 356 | "### Iterators and Generators:\n", 357 | "\n", 358 | "\n", 359 | "#### Iterator:\n", 360 | "\n" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "metadata": {}, 366 | "source": [ 367 | "* Iterator is as same as For loop but the difference the output can be accessed as per requirement.\n", 368 | "* In iterator we have 2 main keywords.\n", 369 | " * iter: to make the value into iteartor\n", 370 | " * Next: for getting the output \n", 371 | " \n", 372 | " " 373 | ] 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 20, 378 | "metadata": {}, 379 | "outputs": [ 380 | { 381 | "name": "stdout", 382 | "output_type": "stream", 383 | "text": [ 384 | "1\n", 385 | "2\n", 386 | "3\n", 387 | "4\n", 388 | "5\n", 389 | "6\n", 390 | "7\n", 391 | "8\n", 392 | "9\n", 393 | "10\n" 394 | ] 395 | } 396 | ], 397 | "source": [ 398 | "### print 1 to 10 numbers.\n", 399 | "\n", 400 | "for i in range(1,11):\n", 401 | " print(i)" 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "execution_count": 21, 407 | "metadata": {}, 408 | "outputs": [], 409 | "source": [ 410 | "### iterator.\n", 411 | "\n", 412 | "l = [i for i in range(1,11)]\n", 413 | "l_iter = iter(l)\n" 414 | ] 415 | }, 416 | { 417 | "cell_type": "code", 418 | "execution_count": 22, 419 | "metadata": {}, 420 | "outputs": [ 421 | { 422 | "data": { 423 | "text/plain": [ 424 | "1" 425 | ] 426 | }, 427 | "execution_count": 22, 428 | "metadata": {}, 429 | "output_type": "execute_result" 430 | } 431 | ], 432 | "source": [ 433 | "next(l_iter)" 434 | ] 435 | }, 436 | { 437 | "cell_type": "code", 438 | "execution_count": 23, 439 | "metadata": {}, 440 | "outputs": [ 441 | { 442 | "data": { 443 | "text/plain": [ 444 | "2" 445 | ] 446 | }, 447 | "execution_count": 23, 448 | "metadata": {}, 449 | "output_type": "execute_result" 450 | } 451 | ], 452 | "source": [ 453 | "next(l_iter)" 454 | ] 455 | }, 456 | { 457 | "cell_type": "code", 458 | "execution_count": 32, 459 | "metadata": {}, 460 | "outputs": [ 461 | { 462 | "ename": "StopIteration", 463 | "evalue": "", 464 | "output_type": "error", 465 | "traceback": [ 466 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 467 | "\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", 468 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ml_iter\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 469 | "\u001b[1;31mStopIteration\u001b[0m: " 470 | ] 471 | } 472 | ], 473 | "source": [ 474 | "next(l_iter)" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": 35, 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "name": "stdout", 484 | "output_type": "stream", 485 | "text": [ 486 | "1\n", 487 | "2\n", 488 | "3\n", 489 | "4\n", 490 | "5\n", 491 | "6\n", 492 | "7\n", 493 | "8\n", 494 | "9\n", 495 | "10\n" 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "a_iter = iter(l)\n", 501 | "while True:\n", 502 | " try : \n", 503 | " item = next(a_iter)\n", 504 | " print(item)\n", 505 | " except StopIteration:\n", 506 | " break\n", 507 | " \n" 508 | ] 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "metadata": {}, 513 | "source": [ 514 | "#### Generator:\n", 515 | "\n", 516 | "* Generator is also like function but in place of return we use yield.\n", 517 | "* Generators are always used in combination with an iterator.\n", 518 | "\n" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": 36, 524 | "metadata": {}, 525 | "outputs": [ 526 | { 527 | "data": { 528 | "text/plain": [ 529 | "4" 530 | ] 531 | }, 532 | "execution_count": 36, 533 | "metadata": {}, 534 | "output_type": "execute_result" 535 | } 536 | ], 537 | "source": [ 538 | "# n = 2 --4\n", 539 | "# n = 4 -- 16\n", 540 | "# n =16 -- 256\n", 541 | "\n", 542 | "def gen(n = 2):\n", 543 | " while True:\n", 544 | " n **= 2\n", 545 | " yield n\n", 546 | "a = gen() \n", 547 | "next(a)" 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "execution_count": 37, 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "16" 559 | ] 560 | }, 561 | "execution_count": 37, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "next(a)" 568 | ] 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 42, 573 | "metadata": {}, 574 | "outputs": [ 575 | { 576 | "data": { 577 | "text/plain": [ 578 | "340282366920938463463374607431768211456" 579 | ] 580 | }, 581 | "execution_count": 42, 582 | "metadata": {}, 583 | "output_type": "execute_result" 584 | } 585 | ], 586 | "source": [ 587 | "next(a)" 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 46, 593 | "metadata": {}, 594 | "outputs": [ 595 | { 596 | "data": { 597 | "text/plain": [ 598 | "4" 599 | ] 600 | }, 601 | "execution_count": 46, 602 | "metadata": {}, 603 | "output_type": "execute_result" 604 | } 605 | ], 606 | "source": [ 607 | "def gen(n = 2):\n", 608 | " while True:\n", 609 | " n **= 2\n", 610 | " return n\n", 611 | "gen()" 612 | ] 613 | }, 614 | { 615 | "cell_type": "markdown", 616 | "metadata": {}, 617 | "source": [ 618 | "#### Generator Comprehension:\n", 619 | "\n" 620 | ] 621 | }, 622 | { 623 | "cell_type": "code", 624 | "execution_count": 49, 625 | "metadata": {}, 626 | "outputs": [ 627 | { 628 | "name": "stdout", 629 | "output_type": "stream", 630 | "text": [ 631 | "1\n", 632 | "35937\n", 633 | "64\n", 634 | "175616\n", 635 | "474552\n", 636 | "729000\n" 637 | ] 638 | } 639 | ], 640 | "source": [ 641 | "li = [1,33,4,56,78,90]\n", 642 | "c = (i**3 for i in li)\n", 643 | "for i in c:\n", 644 | " print(i)" 645 | ] 646 | }, 647 | { 648 | "cell_type": "code", 649 | "execution_count": 53, 650 | "metadata": {}, 651 | "outputs": [ 652 | { 653 | "data": { 654 | "text/plain": [ 655 | "4" 656 | ] 657 | }, 658 | "execution_count": 53, 659 | "metadata": {}, 660 | "output_type": "execute_result" 661 | } 662 | ], 663 | "source": [ 664 | "def gen(n = 2):\n", 665 | " while True:\n", 666 | " n **= 2\n", 667 | " yield n\n", 668 | "a = gen()\n", 669 | "next(a)" 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "execution_count": 54, 675 | "metadata": {}, 676 | "outputs": [ 677 | { 678 | "name": "stdout", 679 | "output_type": "stream", 680 | "text": [ 681 | "1\n", 682 | "35937\n", 683 | "39304\n", 684 | "175616\n", 685 | "343\n", 686 | "512\n" 687 | ] 688 | } 689 | ], 690 | "source": [ 691 | "li=[1,33,34,56,7,8]\n", 692 | "c=(i**3 for i in li)\n", 693 | "for i in c:\n", 694 | " print(i)" 695 | ] 696 | }, 697 | { 698 | "cell_type": "code", 699 | "execution_count": null, 700 | "metadata": {}, 701 | "outputs": [], 702 | "source": [] 703 | } 704 | ], 705 | "metadata": { 706 | "kernelspec": { 707 | "display_name": "Python 3", 708 | "language": "python", 709 | "name": "python3" 710 | }, 711 | "language_info": { 712 | "codemirror_mode": { 713 | "name": "ipython", 714 | "version": 3 715 | }, 716 | "file_extension": ".py", 717 | "mimetype": "text/x-python", 718 | "name": "python", 719 | "nbconvert_exporter": "python", 720 | "pygments_lexer": "ipython3", 721 | "version": "3.7.3" 722 | } 723 | }, 724 | "nbformat": 4, 725 | "nbformat_minor": 2 726 | } 727 | -------------------------------------------------------------------------------- /03-07-2020(Day-11).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Functional Programming\n", 8 | "### lambda\n", 9 | "- Anonymous function\n", 10 | "- Creating a small function\n", 11 | " - syntax: lambda arg1,arg2 : expression" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "30" 23 | ] 24 | }, 25 | "execution_count": 1, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "10 + 20" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "data": { 41 | "text/plain": [ 42 | "30" 43 | ] 44 | }, 45 | "execution_count": 2, 46 | "metadata": {}, 47 | "output_type": "execute_result" 48 | } 49 | ], 50 | "source": [ 51 | "def add1(a,b):\n", 52 | " return a + b\n", 53 | "add1(10,20)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 3, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "add2 = lambda a,b : a + b" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 4, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "30" 74 | ] 75 | }, 76 | "execution_count": 4, 77 | "metadata": {}, 78 | "output_type": "execute_result" 79 | } 80 | ], 81 | "source": [ 82 | "add2(10,20)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 5, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "data": { 92 | "text/plain": [ 93 | "function" 94 | ] 95 | }, 96 | "execution_count": 5, 97 | "metadata": {}, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "type(add1)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 6, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/plain": [ 113 | "function" 114 | ] 115 | }, 116 | "execution_count": 6, 117 | "metadata": {}, 118 | "output_type": "execute_result" 119 | } 120 | ], 121 | "source": [ 122 | "type(add2)" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 7, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/plain": [ 133 | "(a, b)>" 134 | ] 135 | }, 136 | "execution_count": 7, 137 | "metadata": {}, 138 | "output_type": "execute_result" 139 | } 140 | ], 141 | "source": [ 142 | "lambda a,b : a + b" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "- Lambda itself returns a function object" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 8, 155 | "metadata": {}, 156 | "outputs": [ 157 | { 158 | "data": { 159 | "text/plain": [ 160 | "64" 161 | ] 162 | }, 163 | "execution_count": 8, 164 | "metadata": {}, 165 | "output_type": "execute_result" 166 | } 167 | ], 168 | "source": [ 169 | "4 ** 3" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 9, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "cube = lambda a1,b1:a1**b1" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 10, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "64" 190 | ] 191 | }, 192 | "execution_count": 10, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "cube(4,3)" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "## 'if else' in lambda function" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 11, 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "data": { 215 | "text/plain": [ 216 | "True" 217 | ] 218 | }, 219 | "execution_count": 11, 220 | "metadata": {}, 221 | "output_type": "execute_result" 222 | } 223 | ], 224 | "source": [ 225 | "def great(a3):\n", 226 | " if a3 > 10 and a3 < 20:\n", 227 | " return True\n", 228 | " else:\n", 229 | " return False\n", 230 | "great(15)" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 12, 236 | "metadata": {}, 237 | "outputs": [ 238 | { 239 | "data": { 240 | "text/plain": [ 241 | "False" 242 | ] 243 | }, 244 | "execution_count": 12, 245 | "metadata": {}, 246 | "output_type": "execute_result" 247 | } 248 | ], 249 | "source": [ 250 | "great(25)" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 13, 256 | "metadata": {}, 257 | "outputs": [], 258 | "source": [ 259 | "g = lambda a4 : True if(a4 > 10 and a4 < 20) else False" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 14, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "False" 271 | ] 272 | }, 273 | "execution_count": 14, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "g(5)" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 15, 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "data": { 289 | "text/plain": [ 290 | "True" 291 | ] 292 | }, 293 | "execution_count": 15, 294 | "metadata": {}, 295 | "output_type": "execute_result" 296 | } 297 | ], 298 | "source": [ 299 | "g(18)" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 16, 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [ 308 | "n = 10" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 17, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "int" 320 | ] 321 | }, 322 | "execution_count": 17, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "type(n)" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 18, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "name": "stdout", 338 | "output_type": "stream", 339 | "text": [ 340 | "10\n" 341 | ] 342 | } 343 | ], 344 | "source": [ 345 | "n1 = input()" 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "execution_count": 19, 351 | "metadata": {}, 352 | "outputs": [ 353 | { 354 | "data": { 355 | "text/plain": [ 356 | "str" 357 | ] 358 | }, 359 | "execution_count": 19, 360 | "metadata": {}, 361 | "output_type": "execute_result" 362 | } 363 | ], 364 | "source": [ 365 | "type(n1)" 366 | ] 367 | }, 368 | { 369 | "cell_type": "code", 370 | "execution_count": 20, 371 | "metadata": {}, 372 | "outputs": [ 373 | { 374 | "name": "stdout", 375 | "output_type": "stream", 376 | "text": [ 377 | "11\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "n2 = int(input())" 383 | ] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "execution_count": 21, 388 | "metadata": {}, 389 | "outputs": [ 390 | { 391 | "data": { 392 | "text/plain": [ 393 | "int" 394 | ] 395 | }, 396 | "execution_count": 21, 397 | "metadata": {}, 398 | "output_type": "execute_result" 399 | } 400 | ], 401 | "source": [ 402 | "type(n2)" 403 | ] 404 | }, 405 | { 406 | "cell_type": "markdown", 407 | "metadata": {}, 408 | "source": [ 409 | "## Without 'if else' keyword" 410 | ] 411 | }, 412 | { 413 | "cell_type": "code", 414 | "execution_count": 22, 415 | "metadata": {}, 416 | "outputs": [], 417 | "source": [ 418 | "g2 = lambda a5 : (a5 > 10 and a5 < 20)" 419 | ] 420 | }, 421 | { 422 | "cell_type": "code", 423 | "execution_count": 23, 424 | "metadata": {}, 425 | "outputs": [ 426 | { 427 | "data": { 428 | "text/plain": [ 429 | "True" 430 | ] 431 | }, 432 | "execution_count": 23, 433 | "metadata": {}, 434 | "output_type": "execute_result" 435 | } 436 | ], 437 | "source": [ 438 | "g2(16)" 439 | ] 440 | }, 441 | { 442 | "cell_type": "markdown", 443 | "metadata": {}, 444 | "source": [ 445 | "## map()\n", 446 | "- map() function can take user_defined function as a parameter\n", 447 | " - syntax: map(function, iterable1,iterable2,iterable3....)" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": 25, 453 | "metadata": {}, 454 | "outputs": [ 455 | { 456 | "name": "stdout", 457 | "output_type": "stream", 458 | "text": [ 459 | "\n", 460 | "[1, 4, 9, 16]\n" 461 | ] 462 | } 463 | ], 464 | "source": [ 465 | "#[1,2,3,4] ---> 1*1,2*2,3*3,4*4\n", 466 | "\n", 467 | "def mult(a):\n", 468 | " return a*a\n", 469 | "\n", 470 | "x = map(mult,(1,2,3,4))\n", 471 | "print(x) \n", 472 | "print(list(x))" 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": 27, 478 | "metadata": {}, 479 | "outputs": [ 480 | { 481 | "data": { 482 | "text/plain": [ 483 | "['LAVANYA', 'NIHARIKA', 'NAGAMOUNIKA']" 484 | ] 485 | }, 486 | "execution_count": 27, 487 | "metadata": {}, 488 | "output_type": "execute_result" 489 | } 490 | ], 491 | "source": [ 492 | "names = ['lavanya','niharika','nagamounika']\n", 493 | "list(map(str.upper,names))" 494 | ] 495 | }, 496 | { 497 | "cell_type": "markdown", 498 | "metadata": {}, 499 | "source": [ 500 | "### map() with lambda()" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 28, 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "data": { 510 | "text/plain": [ 511 | "[1, 8, 27, 64]" 512 | ] 513 | }, 514 | "execution_count": 28, 515 | "metadata": {}, 516 | "output_type": "execute_result" 517 | } 518 | ], 519 | "source": [ 520 | "list1 = [1,2,3,4]\n", 521 | "list(map(lambda x: x**3, list1))\n", 522 | "# map( function iterable)" 523 | ] 524 | }, 525 | { 526 | "cell_type": "markdown", 527 | "metadata": {}, 528 | "source": [ 529 | "## filter()\n", 530 | "- syntax: filter(function, iterable)" 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "execution_count": 29, 536 | "metadata": {}, 537 | "outputs": [ 538 | { 539 | "data": { 540 | "text/plain": [ 541 | "[2, 4, 6, 8, 10]" 542 | ] 543 | }, 544 | "execution_count": 29, 545 | "metadata": {}, 546 | "output_type": "execute_result" 547 | } 548 | ], 549 | "source": [ 550 | "list2 = [1,2,3,4,5,6,7,8,9,10]\n", 551 | "list(filter(lambda x:(x%2 == 0),list2))" 552 | ] 553 | }, 554 | { 555 | "cell_type": "code", 556 | "execution_count": 31, 557 | "metadata": {}, 558 | "outputs": [ 559 | { 560 | "name": "stdout", 561 | "output_type": "stream", 562 | "text": [ 563 | "[100, 88, 55, 60]\n" 564 | ] 565 | } 566 | ], 567 | "source": [ 568 | "list3 = [10,20,100,26,88,55,49,60]\n", 569 | "def gFunc(x):\n", 570 | " if x >= 50:\n", 571 | " return True\n", 572 | " return False\n", 573 | "\n", 574 | "ans = filter(gFunc,list3)\n", 575 | "print(list(ans))" 576 | ] 577 | }, 578 | { 579 | "cell_type": "markdown", 580 | "metadata": {}, 581 | "source": [ 582 | "- Write the above program using lambda in filter" 583 | ] 584 | }, 585 | { 586 | "cell_type": "markdown", 587 | "metadata": {}, 588 | "source": [ 589 | "## reduce()\n", 590 | "- It is differ from map() in its working\n", 591 | "- syntax: reduce(function, iterables)" 592 | ] 593 | }, 594 | { 595 | "cell_type": "code", 596 | "execution_count": 32, 597 | "metadata": {}, 598 | "outputs": [ 599 | { 600 | "name": "stdout", 601 | "output_type": "stream", 602 | "text": [ 603 | "100\n" 604 | ] 605 | } 606 | ], 607 | "source": [ 608 | "from functools import reduce\n", 609 | "ans = reduce(lambda x,y:x+y,[10,20,30,40])\n", 610 | "print(ans)" 611 | ] 612 | }, 613 | { 614 | "cell_type": "markdown", 615 | "metadata": {}, 616 | "source": [ 617 | "- Take value 'x'
\n", 618 | "if x less than 10,return x * 2
\n", 619 | "else if x is between 10 and 20, return x * 3
\n", 620 | "else return x" 621 | ] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "execution_count": 33, 626 | "metadata": {}, 627 | "outputs": [], 628 | "source": [ 629 | "p = lambda x:x * 2 if x < 10 else (x * 3 if x<20 else x)" 630 | ] 631 | }, 632 | { 633 | "cell_type": "code", 634 | "execution_count": 34, 635 | "metadata": {}, 636 | "outputs": [ 637 | { 638 | "data": { 639 | "text/plain": [ 640 | "22" 641 | ] 642 | }, 643 | "execution_count": 34, 644 | "metadata": {}, 645 | "output_type": "execute_result" 646 | } 647 | ], 648 | "source": [ 649 | "p(22)" 650 | ] 651 | }, 652 | { 653 | "cell_type": "code", 654 | "execution_count": 35, 655 | "metadata": {}, 656 | "outputs": [ 657 | { 658 | "data": { 659 | "text/plain": [ 660 | "36" 661 | ] 662 | }, 663 | "execution_count": 35, 664 | "metadata": {}, 665 | "output_type": "execute_result" 666 | } 667 | ], 668 | "source": [ 669 | "p(12)" 670 | ] 671 | }, 672 | { 673 | "cell_type": "markdown", 674 | "metadata": {}, 675 | "source": [ 676 | "### Task 1\n", 677 | "- list1 = [19,13,90,30,57,190,65,88,155]\n", 678 | "- Return values which is divisible by 19 or 13" 679 | ] 680 | }, 681 | { 682 | "cell_type": "markdown", 683 | "metadata": {}, 684 | "source": [ 685 | "## Task2\n", 686 | "- list2 = ['Nikola','james','albert']\n", 687 | "- list3 = ['tesla','watt','einstein']\n", 688 | "- output: ['Nikola tesla','james watt','albert einstein']" 689 | ] 690 | }, 691 | { 692 | "cell_type": "code", 693 | "execution_count": null, 694 | "metadata": {}, 695 | "outputs": [], 696 | "source": [ 697 | "# if you noted task you can leave session\n", 698 | "# thank you all" 699 | ] 700 | } 701 | ], 702 | "metadata": { 703 | "kernelspec": { 704 | "display_name": "Python 3", 705 | "language": "python", 706 | "name": "python3" 707 | }, 708 | "language_info": { 709 | "codemirror_mode": { 710 | "name": "ipython", 711 | "version": 3 712 | }, 713 | "file_extension": ".py", 714 | "mimetype": "text/x-python", 715 | "name": "python", 716 | "nbconvert_exporter": "python", 717 | "pygments_lexer": "ipython3", 718 | "version": "3.7.3" 719 | } 720 | }, 721 | "nbformat": 4, 722 | "nbformat_minor": 2 723 | } 724 | -------------------------------------------------------------------------------- /04-07-2020(Day-12)/File_handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Day Objectives:\n", 8 | "\n", 9 | "## File Handling :\n", 10 | "\n", 11 | " **File is collection of records**\n", 12 | "![](img.jpg)\n", 13 | "\n", 14 | "\n", 15 | "- Python File Handling: Create, Open, Append, Read, Write\n", 16 | " * Creating a File\n", 17 | " * Write the data \n", 18 | " * Read data from file\n", 19 | " * Append data to file\n", 20 | " \n", 21 | "## Modes of operation:\n", 22 | "\n", 23 | " * 'r' -- Read mode which is used when the file is only being read
\n", 24 | " * 'w' -- Write mode which is used to edit and write new information to the file (any existing files with the same name will be erased when this mode is activated)
\n", 25 | " * 'a' -- Appending mode, which is used to add new data to the end of the file; that is new information is automatically amended to the end
\n", 26 | " * 'r+' -- Special read and write mode, which is used to handle both actions when working with a file\n", 27 | " \n", 28 | "## In-Build function:\n", 29 | "\n", 30 | " * open(path,mode)\n", 31 | " * close()\n", 32 | "\n" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 1, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "# Create a new file\n", 42 | "book = open('book.txt','w')\n", 43 | "book.close()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": 2, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "# write the data into file\n", 53 | "book = open('book.txt','w')\n", 54 | "book.write(\"hi all... ! welcome to APSSDC \")\n", 55 | "book.close()" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 3, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Repalce data \n", 65 | "book = open('book.txt','w')\n", 66 | "book.write(\"welcome to Summer online training \")\n", 67 | "book.close()" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 10, 73 | "metadata": {}, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "'welcome to Summer online training\\nstudent 1\\nstudent 2 \\nstudent 3'" 79 | ] 80 | }, 81 | "execution_count": 10, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "# Read entaire data at a time\n", 88 | "book = open('book.txt','r')\n", 89 | "book.read()" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 11, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "welcome to Summer online training\n", 102 | "\n", 103 | "student 1\n", 104 | "\n", 105 | "student 2 \n", 106 | "\n", 107 | "student 3\n" 108 | ] 109 | } 110 | ], 111 | "source": [ 112 | "# read the data from file line by line\n", 113 | "book = open('book.txt','r')\n", 114 | "#book.readlines()\n", 115 | "for line in book.readlines():\n", 116 | " print(line)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 13, 122 | "metadata": {}, 123 | "outputs": [ 124 | { 125 | "name": "stdout", 126 | "output_type": "stream", 127 | "text": [ 128 | "w e l c o m e t o S u m m e r o n l i n e t r a i n i n g \n", 129 | " " 130 | ] 131 | } 132 | ], 133 | "source": [ 134 | "# read the data character by character\n", 135 | "book = open('book.txt','r')\n", 136 | "for char in book.readline():\n", 137 | " print(char, end = ' ')" 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": 39, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "# append the data at the end \n", 147 | "book = open('book.txt','a')\n", 148 | "book.write(\"\\nstudent 5\")\n", 149 | "book.close()" 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 19, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "book = open('book.txt','a')\n", 159 | "for i in range(6,51):\n", 160 | " book.write(\"student %d\\n\"%(i))\n", 161 | " " 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "book = open('book.txt','r+')\n", 169 | "\n", 170 | "book.read()\n", 171 | "book.write(\"hi hii hi\")\n", 172 | "book.close()" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "execution_count": null, 199 | "metadata": {}, 200 | "outputs": [], 201 | "source": [] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "## Methods in file handling\n", 208 | "* tell(): returns the current location of pointer\n", 209 | "* seek(): we can set the pointer at a specific location " 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 40, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "name": "stdout", 219 | "output_type": "stream", 220 | "text": [ 221 | "0\n", 222 | "hi \n", 223 | "\n", 224 | "4\n", 225 | "student 5\n", 226 | "\n", 227 | "14\n" 228 | ] 229 | } 230 | ], 231 | "source": [ 232 | "book = open('book.txt','r')\n", 233 | "print(book.tell())\n", 234 | "print(book.readline())\n", 235 | "print(book.tell())\n", 236 | "print(book.readline())\n", 237 | "print(book.tell())" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 43, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "name": "stdout", 247 | "output_type": "stream", 248 | "text": [ 249 | "i \n", 250 | "\n", 251 | "6\n", 252 | "udent 5\n", 253 | "\n" 254 | ] 255 | } 256 | ], 257 | "source": [ 258 | "book = open('book.txt','r')\n", 259 | "book.seek(1)\n", 260 | "print(book.readline())\n", 261 | "print(book.seek(6))\n", 262 | "print(book.readline())" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 55, 268 | "metadata": {}, 269 | "outputs": [], 270 | "source": [ 271 | "mail = open('mail.txt','w')\n", 272 | "mail.write(\"lavanya_p@apssdc.in\")\n", 273 | "mail.close()" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": 59, 279 | "metadata": {}, 280 | "outputs": [ 281 | { 282 | "data": { 283 | "text/plain": [ 284 | "9" 285 | ] 286 | }, 287 | "execution_count": 59, 288 | "metadata": {}, 289 | "output_type": "execute_result" 290 | } 291 | ], 292 | "source": [ 293 | "mail = open('mail.txt','r')\n", 294 | "li = list(mail.read())\n", 295 | "li.index('@')\n", 296 | "mail.seek(li.index('@')+1)\n", 297 | "mail.readlines()" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 60, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/plain": [ 308 | "9" 309 | ] 310 | }, 311 | "execution_count": 60, 312 | "metadata": {}, 313 | "output_type": "execute_result" 314 | } 315 | ], 316 | "source": [ 317 | "li.index('@')" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 61, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "data": { 327 | "text/plain": [ 328 | "['apssdc.in']" 329 | ] 330 | }, 331 | "execution_count": 61, 332 | "metadata": {}, 333 | "output_type": "execute_result" 334 | } 335 | ], 336 | "source": [ 337 | "mail.seek(li.index('@')+1)\n", 338 | "mail.readlines()" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 63, 344 | "metadata": {}, 345 | "outputs": [], 346 | "source": [ 347 | "mail = open('mail.txt','r+')\n", 348 | "li = list(mail.read())\n", 349 | "li.index('@')\n", 350 | "mail.seek(li.index('@')+1)\n", 351 | "mail.write(\"official\")\n", 352 | "mail.close()" 353 | ] 354 | }, 355 | { 356 | "cell_type": "code", 357 | "execution_count": null, 358 | "metadata": {}, 359 | "outputs": [], 360 | "source": [] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "### Data handling:\n", 367 | " * Line count - TO find lines in a file\n", 368 | " * Word count - To find the count of char \n", 369 | " * Char count - To find the count spl char" 370 | ] 371 | }, 372 | { 373 | "cell_type": "code", 374 | "execution_count": 69, 375 | "metadata": {}, 376 | "outputs": [ 377 | { 378 | "name": "stdout", 379 | "output_type": "stream", 380 | "text": [ 381 | "5\n" 382 | ] 383 | } 384 | ], 385 | "source": [ 386 | "# To find lines in a file\n", 387 | "mail = open('book.txt','r')\n", 388 | "count = 0\n", 389 | "for line in mail.readlines():\n", 390 | " count += 1\n", 391 | " #print(line)\n", 392 | " \n", 393 | "print(count)" 394 | ] 395 | }, 396 | { 397 | "cell_type": "code", 398 | "execution_count": 87, 399 | "metadata": { 400 | "collapsed": true 401 | }, 402 | "outputs": [ 403 | { 404 | "name": "stdout", 405 | "output_type": "stream", 406 | "text": [ 407 | "h\n", 408 | "i\n", 409 | " \n", 410 | "\n", 411 | "\n", 412 | "s\n", 413 | "t\n", 414 | "u\n", 415 | "d\n", 416 | "e\n", 417 | "n\n", 418 | "t\n", 419 | " \n", 420 | "5\n", 421 | "\n", 422 | "\n", 423 | "h\n", 424 | "e\n", 425 | "l\n", 426 | "l\n", 427 | "o\n", 428 | "\n", 429 | "\n", 430 | "h\n", 431 | "e\n", 432 | "l\n", 433 | "l\n", 434 | "o\n", 435 | "o\n", 436 | "o\n", 437 | "o\n", 438 | "o\n", 439 | "o\n", 440 | "o\n", 441 | "o\n", 442 | "o\n", 443 | "o\n", 444 | "o\n", 445 | "o\n", 446 | "\n", 447 | "\n", 448 | "n\n", 449 | "f\n", 450 | "d\n", 451 | "g\n", 452 | "f\n", 453 | "g\n", 454 | "h\n", 455 | "Total 44 char in file \n" 456 | ] 457 | } 458 | ], 459 | "source": [ 460 | "# To find characters in a flie\n", 461 | "mail = open('book.txt','r')\n", 462 | "count = 0\n", 463 | "for char in mail.read():\n", 464 | " count += 1\n", 465 | " print(char)\n", 466 | " \n", 467 | "print(\"Total {0} char in file \".format(count))\n", 468 | "#print(count)" 469 | ] 470 | }, 471 | { 472 | "cell_type": "code", 473 | "execution_count": 93, 474 | "metadata": {}, 475 | "outputs": [], 476 | "source": [ 477 | "# To find Total number of Alpha and numerics in file\n" 478 | ] 479 | }, 480 | { 481 | "cell_type": "code", 482 | "execution_count": 92, 483 | "metadata": {}, 484 | "outputs": [ 485 | { 486 | "name": "stdout", 487 | "output_type": "stream", 488 | "text": [ 489 | "Total 37 alphabets and 7 digits\n" 490 | ] 491 | } 492 | ], 493 | "source": [ 494 | "book=open('book.txt','r')\n", 495 | "c=0\n", 496 | "c1=0\n", 497 | "for char in book.read():\n", 498 | " if char.isalpha():\n", 499 | " c=c+1\n", 500 | " if char.isdigit():\n", 501 | " c1=c1+1\n", 502 | " \n", 503 | "print(\"Total {0} alphabets and {1} digits\".format(c,c1))\n", 504 | "#print(c1)\n", 505 | "book.close()\n" 506 | ] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "execution_count": 94, 511 | "metadata": {}, 512 | "outputs": [ 513 | { 514 | "name": "stdout", 515 | "output_type": "stream", 516 | "text": [ 517 | "9\n" 518 | ] 519 | } 520 | ], 521 | "source": [ 522 | "# Find only special char in a file\n", 523 | "book=open('book.txt','r')\n", 524 | "c=0\n", 525 | "c1=0\n", 526 | "c2=0\n", 527 | "for char in book.read():\n", 528 | " if char.isalpha():\n", 529 | " c+=1\n", 530 | " elif char.isdigit():\n", 531 | " c1+=1\n", 532 | " else:\n", 533 | " c2+=1\n", 534 | "print(c2)\n", 535 | "book.close()\n" 536 | ] 537 | }, 538 | { 539 | "cell_type": "code", 540 | "execution_count": 99, 541 | "metadata": {}, 542 | "outputs": [ 543 | { 544 | "name": "stdout", 545 | "output_type": "stream", 546 | "text": [ 547 | "Total 9 special characters\n" 548 | ] 549 | } 550 | ], 551 | "source": [ 552 | "# Another process\n", 553 | "book=open('book.txt','r')\n", 554 | "c2=0\n", 555 | "for char in book.read():\n", 556 | " if char.isalpha() or char.isdigit():\n", 557 | " pass\n", 558 | " else:\n", 559 | " c2 += 1\n", 560 | "print('Total {0} special characters'.format(c2))\n", 561 | "book.close()" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": null, 567 | "metadata": {}, 568 | "outputs": [], 569 | "source": [] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "execution_count": null, 574 | "metadata": {}, 575 | "outputs": [], 576 | "source": [] 577 | }, 578 | { 579 | "cell_type": "code", 580 | "execution_count": null, 581 | "metadata": {}, 582 | "outputs": [], 583 | "source": [] 584 | }, 585 | { 586 | "cell_type": "code", 587 | "execution_count": null, 588 | "metadata": {}, 589 | "outputs": [], 590 | "source": [] 591 | }, 592 | { 593 | "cell_type": "markdown", 594 | "metadata": {}, 595 | "source": [ 596 | "## Task\n", 597 | "### display the student phone number who given invalid mobile \n", 598 | "### numbers in contacts.txt\n", 599 | "\n" 600 | ] 601 | }, 602 | { 603 | "cell_type": "code", 604 | "execution_count": 101, 605 | "metadata": {}, 606 | "outputs": [], 607 | "source": [ 608 | "phonebook = open('phone.txt','w')\n", 609 | "phonebook.write(\"sai 9876543210\\n\")\n", 610 | "phonebook.write(\"ameer 1234567890\\n\")\n", 611 | "phonebook.write(\"janardhana 658357465874\")\n", 612 | "phonebook.close()" 613 | ] 614 | }, 615 | { 616 | "cell_type": "code", 617 | "execution_count": 102, 618 | "metadata": {}, 619 | "outputs": [], 620 | "source": [ 621 | "import re" 622 | ] 623 | }, 624 | { 625 | "cell_type": "code", 626 | "execution_count": 130, 627 | "metadata": {}, 628 | "outputs": [], 629 | "source": [ 630 | "def phoneValidation(number):\n", 631 | " if re.search(\"^[6-9]{1}[0-9]{9}$\",number):\n", 632 | " pass\n", 633 | " else:\n", 634 | " return number\n", 635 | "\n", 636 | "phoneValidation('9876543210')" 637 | ] 638 | }, 639 | { 640 | "cell_type": "code", 641 | "execution_count": 132, 642 | "metadata": {}, 643 | "outputs": [ 644 | { 645 | "name": "stdout", 646 | "output_type": "stream", 647 | "text": [ 648 | "None\n", 649 | "1234567890\n", 650 | "658357465874\n" 651 | ] 652 | } 653 | ], 654 | "source": [ 655 | "phonebook = open('phone.txt','r')\n", 656 | "for line in phonebook.readlines():\n", 657 | " l = line.split()\n", 658 | " for i in l:\n", 659 | " if i.isdigit():\n", 660 | " print(phoneValidation(i))\n" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "execution_count": null, 666 | "metadata": {}, 667 | "outputs": [], 668 | "source": [ 669 | "# marks Task\n", 670 | "\n", 671 | "# marks.txt\n", 672 | "student_name maths english\n", 673 | "sai 90 45\n", 674 | "ameer 89 54\n", 675 | "harika 56 90\n", 676 | "\n", 677 | "\n", 678 | "#output \n", 679 | "\n", 680 | "#report.txt\n", 681 | "student_name maths english Total \n", 682 | "sai 90 45 135\n", 683 | "ameer 89 54 143\n", 684 | "harika 56 90 146\n", 685 | "\n", 686 | "sai.chandu7306@gmail.com\n", 687 | "hemalata7522@gmail.com \n", 688 | "harikacdm@gmail.com\n", 689 | "jana34324@gmail.com\n", 690 | "sowndaryamahasivabattu@gmail.com\n", 691 | "Kiranmaisanaboyina9@gmail.com\n", 692 | "devireddy.charanreddy@gmail.com " 693 | ] 694 | }, 695 | { 696 | "cell_type": "code", 697 | "execution_count": 133, 698 | "metadata": {}, 699 | "outputs": [ 700 | { 701 | "data": { 702 | "text/plain": [ 703 | "" 704 | ] 705 | }, 706 | "execution_count": 133, 707 | "metadata": {}, 708 | "output_type": "execute_result" 709 | } 710 | ], 711 | "source": [ 712 | "# Sowjanya$123\n", 713 | "re.search(\"^[A-Z]{1}[a-z]{5,10}$\",\"Sowjanya\")" 714 | ] 715 | }, 716 | { 717 | "cell_type": "code", 718 | "execution_count": null, 719 | "metadata": {}, 720 | "outputs": [], 721 | "source": [] 722 | } 723 | ], 724 | "metadata": { 725 | "kernelspec": { 726 | "display_name": "Python 3", 727 | "language": "python", 728 | "name": "python3" 729 | }, 730 | "language_info": { 731 | "codemirror_mode": { 732 | "name": "ipython", 733 | "version": 3 734 | }, 735 | "file_extension": ".py", 736 | "mimetype": "text/x-python", 737 | "name": "python", 738 | "nbconvert_exporter": "python", 739 | "pygments_lexer": "ipython3", 740 | "version": "3.7.3" 741 | } 742 | }, 743 | "nbformat": 4, 744 | "nbformat_minor": 2 745 | } 746 | -------------------------------------------------------------------------------- /04-07-2020(Day-12)/book.txt: -------------------------------------------------------------------------------- 1 | hi 2 | student 5 3 | hello 4 | helloooooooooooo 5 | nfdgfgh # 576657 -------------------------------------------------------------------------------- /04-07-2020(Day-12)/img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/04-07-2020(Day-12)/img.jpg -------------------------------------------------------------------------------- /04-07-2020(Day-12)/mail.txt: -------------------------------------------------------------------------------- 1 | lavanya_p@officialn -------------------------------------------------------------------------------- /04-07-2020(Day-12)/phone.txt: -------------------------------------------------------------------------------- 1 | sai 9876543210 2 | ameer 1234567890 3 | janardhana 658357465874 -------------------------------------------------------------------------------- /07-07-2020(Day-15)/data_Concat.csv: -------------------------------------------------------------------------------- 1 | ,state,cases 2 | 11,ap,100 3 | 22,tm,200 4 | 33,kerala,300 5 | 11,a,10 6 | 22,t,20 7 | 33,k,30 8 | -------------------------------------------------------------------------------- /08-07-2020(Day-16)/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/08-07-2020(Day-16)/logo.png -------------------------------------------------------------------------------- /09-07-2020(Day-17)/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/09-07-2020(Day-17)/download.png -------------------------------------------------------------------------------- /10-07-2020(Day-18)/inheritence.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/10-07-2020(Day-18)/inheritence.jpg -------------------------------------------------------------------------------- /10-07-2020(Day-18)/multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/10-07-2020(Day-18)/multi.png -------------------------------------------------------------------------------- /10-07-2020(Day-18)/multilevel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/10-07-2020(Day-18)/multilevel.jpg -------------------------------------------------------------------------------- /10-07-2020(Day-18)/single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3/1912cce1f540aee16b23d431a78b4126cd5fe588/10-07-2020(Day-18)/single.png -------------------------------------------------------------------------------- /1st July 2020.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Modules and packages\n", 8 | "#### Modules\n", 9 | "- a single python containing functions\n", 10 | "#### Packages\n", 11 | "- Collection of modules" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 2, 17 | "metadata": {}, 18 | "outputs": [ 19 | { 20 | "data": { 21 | "text/plain": [ 22 | "10.0" 23 | ] 24 | }, 25 | "execution_count": 2, 26 | "metadata": {}, 27 | "output_type": "execute_result" 28 | } 29 | ], 30 | "source": [ 31 | "# from package import module\n", 32 | "from math import sqrt \n", 33 | "sqrt(100)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 5, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "10.0" 45 | ] 46 | }, 47 | "execution_count": 5, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "import math\n", 54 | "math.sqrt(100)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "52\n", 67 | "45\n", 68 | "59\n", 69 | "1\n", 70 | "4\n", 71 | "89\n", 72 | "59\n", 73 | "49\n", 74 | "84\n", 75 | "68\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "import random\n", 81 | "# from random import randint\n", 82 | "def generateNumbers(n,lowlimit,uplimit):\n", 83 | " for i in range(n):\n", 84 | " print(random.randint(lowlimit,uplimit))\n", 85 | "generateNumbers(10,1,100)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 4, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "10.0" 97 | ] 98 | }, 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "import math\n", 106 | "math.sqrt(100)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "### Regular Expressions\n", 114 | "- A regular expression is a sequence of characters that match a pattern\n", 115 | "- import re\n", 116 | "- Character - usecase\n", 117 | " >1. ^ - matches the begining\n", 118 | " >2. [] - represents a character\n", 119 | " >3. . - matches single character\n", 120 | " >4. + - one or more no of occurences \n", 121 | " >5. * - zero or more occurences\n", 122 | " >6. {} - range set\n", 123 | " >7.$ - matches the ending " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 12, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "enterafgh\n", 136 | "matched\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "# jagadish\n", 142 | "# harish\n", 143 | "# ah\n", 144 | "# ^[a-zA-Z][a-z]* [h]$\n", 145 | "import re\n", 146 | "pattern = '^[a-zA-Z][a-z]*[h]$'\n", 147 | "ch = input(\"enter\")\n", 148 | "if re.match(pattern,ch):\n", 149 | " print(\"matched\") \n", 150 | "else:\n", 151 | " print(\"not matched\")" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 13, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [ 160 | "import re" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 14, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "re.match(\"hi\",\"joy\")" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 15, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "" 181 | ] 182 | }, 183 | "execution_count": 15, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "re.match(\"hi\",\"hi\")" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 16, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "re.match(\"python\",\"pytho\")" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 17, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "" 210 | ] 211 | }, 212 | "execution_count": 17, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "re.match(\"p\",\"python\")" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 18, 224 | "metadata": {}, 225 | "outputs": [], 226 | "source": [ 227 | "re.match(\"y\",\"python\")" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 19, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "" 239 | ] 240 | }, 241 | "execution_count": 19, 242 | "metadata": {}, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "re.search(\"p\",\"python\")" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 21, 253 | "metadata": {}, 254 | "outputs": [ 255 | { 256 | "data": { 257 | "text/plain": [ 258 | "" 259 | ] 260 | }, 261 | "execution_count": 21, 262 | "metadata": {}, 263 | "output_type": "execute_result" 264 | } 265 | ], 266 | "source": [ 267 | "re.search(\"ho\",\"python\")" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 22, 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "" 279 | ] 280 | }, 281 | "execution_count": 22, 282 | "metadata": {}, 283 | "output_type": "execute_result" 284 | } 285 | ], 286 | "source": [ 287 | "re.search(\"o\",\"workshop\")" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 24, 293 | "metadata": {}, 294 | "outputs": [ 295 | { 296 | "data": { 297 | "text/plain": [ 298 | "['o', 'o', 'o', 'o']" 299 | ] 300 | }, 301 | "execution_count": 24, 302 | "metadata": {}, 303 | "output_type": "execute_result" 304 | } 305 | ], 306 | "source": [ 307 | "re.findall(\"o\",\"workosohop\")" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 25, 313 | "metadata": {}, 314 | "outputs": [], 315 | "source": [ 316 | "# match - searches the begining character\n", 317 | "# search - seraches the string until it founds and skips remaining search\n", 318 | "# findall - seraches the entire string if it has found already " 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 30, 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "name": "stdout", 328 | "output_type": "stream", 329 | "text": [ 330 | "enterand\n", 331 | "matched\n" 332 | ] 333 | } 334 | ], 335 | "source": [ 336 | "# anand\n", 337 | "# and\n", 338 | "# anacond\n", 339 | "# awkward\n", 340 | "import re\n", 341 | "pattern = '^[a][a-z]*[d]$'\n", 342 | "ch = input(\"enter\")\n", 343 | "if re.match(pattern,ch):\n", 344 | " print(\"matched\") \n", 345 | "else:\n", 346 | " print(\"not matched\")" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 37, 352 | "metadata": {}, 353 | "outputs": [ 354 | { 355 | "name": "stdout", 356 | "output_type": "stream", 357 | "text": [ 358 | "enter +916789012345\n" 359 | ] 360 | }, 361 | { 362 | "data": { 363 | "text/plain": [ 364 | "True" 365 | ] 366 | }, 367 | "execution_count": 37, 368 | "metadata": {}, 369 | "output_type": "execute_result" 370 | } 371 | ], 372 | "source": [ 373 | "# 10 digits - 6789123450 - ^[6-9][0-9]{9}$\n", 374 | "# 11 digits - 06789123457 - ^[0][6-9][0-9]{9}$\n", 375 | "# 12 digits - +916789012345 - ^[+][9][1][6-9][0-9]{9}$\n", 376 | "def phonenumber(number):\n", 377 | " pattern = '^[6-9][0-9]{9}$|^[0][6-9][0-9]{9}$|^[+][9][1][6-9][0-9]{9}$'\n", 378 | " if re.match(pattern,number):\n", 379 | " return True\n", 380 | " return False\n", 381 | " \n", 382 | "\n", 383 | "number = input(\"enter \")\n", 384 | "phonenumber(number)" 385 | ] 386 | }, 387 | { 388 | "cell_type": "code", 389 | "execution_count": 40, 390 | "metadata": {}, 391 | "outputs": [ 392 | { 393 | "name": "stdout", 394 | "output_type": "stream", 395 | "text": [ 396 | "enter abcef.@hai.in\n" 397 | ] 398 | }, 399 | { 400 | "data": { 401 | "text/plain": [ 402 | "False" 403 | ] 404 | }, 405 | "execution_count": 40, 406 | "metadata": {}, 407 | "output_type": "execute_result" 408 | } 409 | ], 410 | "source": [ 411 | "# email validation - abcedf@gmail.com\n", 412 | "# abcedf - username - [a-z0-9_.], 16 ---- ^[a-z0-9][a-z0-9_.]{4,16}[0-9a-z]\n", 413 | "# gmail - domain/organization - [a-z0-9]{5,18}\n", 414 | "# com - extension (in,army) - [a-z]{2,5}$\n", 415 | "def emailValidation(email):\n", 416 | " pattern = '^[a-z0-9][a-z0-9_.]{4,16}[0-9a-z][@][a-z0-9]{5,18}[.][a-z]{2,5}$'\n", 417 | " if re.match(pattern,email):\n", 418 | " return True\n", 419 | " return False\n", 420 | " \n", 421 | "\n", 422 | "email = input(\"enter \")\n", 423 | "emailValidation(email)" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": null, 429 | "metadata": {}, 430 | "outputs": [], 431 | "source": [ 432 | "# to add a contact which is not in contacts list \n", 433 | "# search a contact in contacts list" 434 | ] 435 | } 436 | ], 437 | "metadata": { 438 | "kernelspec": { 439 | "display_name": "Python 3", 440 | "language": "python", 441 | "name": "python3" 442 | }, 443 | "language_info": { 444 | "codemirror_mode": { 445 | "name": "ipython", 446 | "version": 3 447 | }, 448 | "file_extension": ".py", 449 | "mimetype": "text/x-python", 450 | "name": "python", 451 | "nbconvert_exporter": "python", 452 | "pygments_lexer": "ipython3", 453 | "version": "3.7.1" 454 | } 455 | }, 456 | "nbformat": 4, 457 | "nbformat_minor": 2 458 | } 459 | -------------------------------------------------------------------------------- /22-06-2020(Day-1).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Python Introduction:\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "* High Level Language:
\n", 16 | " * The language which can be understandable by user/human.\n", 17 | "* Low Level Language:
\n", 18 | " * The language which can be understand by a Processor/machine (0's and 1's)\n", 19 | " \n", 20 | "#### Python:\n", 21 | "\n", 22 | "* Python is a high level language.\n", 23 | "* The founder of python is guido van rossum\n", 24 | "* The Python was implemented in the year 1994.\n", 25 | "\n", 26 | "### Python versions:\n", 27 | "\n", 28 | "* Version 1 ---- 1994\n", 29 | "* Version 2 ---- 2000\n", 30 | "* Version 3 ---- 2008\n", 31 | "* Version 3.8 ---- 2019\n", 32 | "\n", 33 | "#### Why Python?\n", 34 | "\n", 35 | "* Python easy and simple to learn and develop.\n", 36 | "* Supports Object Oriented Language\n", 37 | "* Platform independent.(Jupyter,Python Idle,Pycharm,COlabs)\n", 38 | "* More number of libraries(Pandas,Numpy,Matplotlib,scipy and so on)\n", 39 | "* Open Source and Easy to Understand.\n", 40 | "* Develop different type of applications like web applications,Machine Learning,Data Science,Internet of Things,Artificial Intelligence" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [] 47 | } 48 | ], 49 | "metadata": { 50 | "kernelspec": { 51 | "display_name": "Python 3", 52 | "language": "python", 53 | "name": "python3" 54 | }, 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.7.3" 66 | } 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 2 70 | } 71 | -------------------------------------------------------------------------------- /22-06-2020/22-06-2020(Day-1).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Python Introduction:\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "* High Level Language:
\n", 16 | " * The language which can be understandable by user/human.\n", 17 | "* Low Level Language:
\n", 18 | " * The language which can be understand by a Processor/machine (0's and 1's)\n", 19 | " \n", 20 | "#### Python:\n", 21 | "\n", 22 | "* Python is a high level language.\n", 23 | "* The founder of python is guido van rossum\n", 24 | "* The Python was implemented in the year 1994.\n", 25 | "\n", 26 | "### Python versions:\n", 27 | "\n", 28 | "* Version 1 ---- 1994\n", 29 | "* Version 2 ---- 2000\n", 30 | "* Version 3 ---- 2008\n", 31 | "* Version 3.8 ---- 2019\n", 32 | "\n", 33 | "#### Why Python?\n", 34 | "\n", 35 | "* Python easy and simple to learn and develop.\n", 36 | "* Supports Object Oriented Language\n", 37 | "* Platform independent.(Jupyter,Python Idle,Pycharm,COlabs)\n", 38 | "* More number of libraries(Pandas,Numpy,Matplotlib,scipy and so on)\n", 39 | "* Open Source and Easy to Understand.\n", 40 | "* Develop different type of applications like web applications,Machine Learning,Data Science,Internet of Things,Artificial Intelligence" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [] 47 | } 48 | ], 49 | "metadata": { 50 | "kernelspec": { 51 | "display_name": "Python 3", 52 | "language": "python", 53 | "name": "python3" 54 | }, 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.7.3" 66 | } 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 2 70 | } 71 | -------------------------------------------------------------------------------- /24-06-2020(Day-3).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Operators\n", 8 | "### Arithmetic - +,-,*,/,%,//,**\n", 9 | "### logical - and, or, not\n", 10 | "### Assignment - +=,-=,/=,*=,%=,//=,**=,=\n", 11 | "### bitwise - &,|,^,~,<<,>>\n", 12 | "### comparision - ==,!=,<=,>=,>,<\n", 13 | "### identity - is, is not\n", 14 | "### Membership - in , not in" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 5, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "2\n", 27 | "25\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "a = 5\n", 33 | "b=2\n", 34 | "print(a//b)\n", 35 | "print(5**2)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 6, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "False" 47 | ] 48 | }, 49 | "execution_count": 6, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "2>5 and 4<5" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 8, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "False" 67 | ] 68 | }, 69 | "execution_count": 8, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "not(2>5 or 4<5)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 9, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#a = a+1\n", 85 | "a += 1" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 10, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "6" 97 | ] 98 | }, 99 | "execution_count": 10, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "a" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 15, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "name": "stdout", 115 | "output_type": "stream", 116 | "text": [ 117 | "2\n", 118 | "3\n", 119 | "1\n", 120 | "-3\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "x = 2\n", 126 | "y = 3\n", 127 | "print(x&y)\n", 128 | "print(x|y)\n", 129 | "print(x^y)\n", 130 | "print(~x)\n", 131 | "# 0010\n", 132 | "# 0011\n", 133 | "# 0010" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 13, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "16" 145 | ] 146 | }, 147 | "execution_count": 13, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "x<>x\n", 176 | "# 0011\n", 177 | "# 0000" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 16, 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "data": { 187 | "text/plain": [ 188 | "True" 189 | ] 190 | }, 191 | "execution_count": 16, 192 | "metadata": {}, 193 | "output_type": "execute_result" 194 | } 195 | ], 196 | "source": [ 197 | "\"hai\" < \"hi\"" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 17, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "data": { 207 | "text/plain": [ 208 | "False" 209 | ] 210 | }, 211 | "execution_count": 17, 212 | "metadata": {}, 213 | "output_type": "execute_result" 214 | } 215 | ], 216 | "source": [ 217 | "\"a\" > \"k\"" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 19, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "data": { 227 | "text/plain": [ 228 | "True" 229 | ] 230 | }, 231 | "execution_count": 19, 232 | "metadata": {}, 233 | "output_type": "execute_result" 234 | } 235 | ], 236 | "source": [ 237 | "\"abc\" != \"ABC\"" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 20, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "data": { 247 | "text/plain": [ 248 | "True" 249 | ] 250 | }, 251 | "execution_count": 20, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "\"a\" is \"a\"" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 29, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "False\n" 270 | ] 271 | }, 272 | { 273 | "data": { 274 | "text/plain": [ 275 | "True" 276 | ] 277 | }, 278 | "execution_count": 29, 279 | "metadata": {}, 280 | "output_type": "execute_result" 281 | } 282 | ], 283 | "source": [ 284 | "print(5 is 55)\n", 285 | "5 is not 55" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 27, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "data": { 295 | "text/plain": [ 296 | "True" 297 | ] 298 | }, 299 | "execution_count": 27, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "a = 3\n", 306 | "b = 3\n", 307 | "c = 78\n", 308 | "a is b" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 24, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "140727498355600" 320 | ] 321 | }, 322 | "execution_count": 24, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "id(a)" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 28, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "140727498358000" 340 | ] 341 | }, 342 | "execution_count": 28, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "id(c)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 30, 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "data": { 358 | "text/plain": [ 359 | "True" 360 | ] 361 | }, 362 | "execution_count": 30, 363 | "metadata": {}, 364 | "output_type": "execute_result" 365 | } 366 | ], 367 | "source": [ 368 | "\"A\" in \"apssdcA\"" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 31, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "True" 380 | ] 381 | }, 382 | "execution_count": 31, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "l = [1,2,3,4,5]\n", 389 | "5 in l" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": 33, 395 | "metadata": {}, 396 | "outputs": [ 397 | { 398 | "data": { 399 | "text/plain": [ 400 | "False" 401 | ] 402 | }, 403 | "execution_count": 33, 404 | "metadata": {}, 405 | "output_type": "execute_result" 406 | } 407 | ], 408 | "source": [ 409 | "s = \"python\"\n", 410 | "\"o\" not in s" 411 | ] 412 | }, 413 | { 414 | "cell_type": "markdown", 415 | "metadata": {}, 416 | "source": [ 417 | "# Conditional Statements\n", 418 | "#### if\n", 419 | "#### if-else\n", 420 | "#### elif\n", 421 | "#### nested if" 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "execution_count": null, 427 | "metadata": {}, 428 | "outputs": [], 429 | "source": [ 430 | "# elif syntax\n", 431 | "if condition:\n", 432 | " statements\n", 433 | "elif condition:\n", 434 | " statements\n", 435 | "else:\n", 436 | " statements" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 1, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "name": "stdout", 446 | "output_type": "stream", 447 | "text": [ 448 | "enter n3\n", 449 | "positive\n" 450 | ] 451 | } 452 | ], 453 | "source": [ 454 | "n = int(input(\"enter n\"))\n", 455 | "if n>0:\n", 456 | " print(\"positive\")\n", 457 | "elif n<0:\n", 458 | " print(\"negative\")\n", 459 | "else:\n", 460 | " print(\"zero\")" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 5, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "name": "stdout", 470 | "output_type": "stream", 471 | "text": [ 472 | "2\n", 473 | "3\n", 474 | "6\n", 475 | "6 is large\n" 476 | ] 477 | } 478 | ], 479 | "source": [ 480 | "a = int(input(\"enter a \"))\n", 481 | "b = int(input(\"enter b\"))\n", 482 | "c = int(input(\"enter c\"))\n", 483 | "if a>b and a>c:\n", 484 | " print(a,\"is large\")\n", 485 | "elif b>c:\n", 486 | " print(b,\"is large\")\n", 487 | "else:\n", 488 | " print(c,\"is large\")" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": 7, 494 | "metadata": {}, 495 | "outputs": [ 496 | { 497 | "name": "stdout", 498 | "output_type": "stream", 499 | "text": [ 500 | "enter usernamesdfghjnm\n", 501 | "enter passowrdxcvbnm,\n", 502 | "invalid username or password\n" 503 | ] 504 | } 505 | ], 506 | "source": [ 507 | "uname = \"apssdc\"\n", 508 | "pwd = \"1234\"\n", 509 | "username = input(\"enter username\")\n", 510 | "password = input(\"enter passowrd\")\n", 511 | "if uname == username and pwd == password:\n", 512 | " print(\"welcome \"+username+\" for login\")\n", 513 | "else:\n", 514 | " print(\"invalid username or password\")\n", 515 | " " 516 | ] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "execution_count": null, 521 | "metadata": {}, 522 | "outputs": [], 523 | "source": [ 524 | "# for loop syntax\n", 525 | "for i in range(start,stop,step):\n", 526 | " statements\n", 527 | "# range(stop)\n", 528 | "# range(start,stop)\n", 529 | "# range(start,stop,step)" 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": 9, 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "0\n", 542 | "1\n", 543 | "2\n", 544 | "3\n", 545 | "4\n", 546 | "5\n", 547 | "6\n", 548 | "7\n", 549 | "8\n", 550 | "9\n", 551 | "10\n" 552 | ] 553 | } 554 | ], 555 | "source": [ 556 | "for i in range(10+1):\n", 557 | " print(i)" 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "execution_count": 14, 563 | "metadata": {}, 564 | "outputs": [ 565 | { 566 | "name": "stdout", 567 | "output_type": "stream", 568 | "text": [ 569 | "11\n", 570 | "\n", 571 | "14\n", 572 | "\n", 573 | "17\n", 574 | "\n", 575 | "20\n", 576 | "\n" 577 | ] 578 | } 579 | ], 580 | "source": [ 581 | "for i in range(11,21,3):\n", 582 | " print(i)\n", 583 | " print()" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 13, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "name": "stdout", 593 | "output_type": "stream", 594 | "text": [ 595 | "10 8 6 4 2 " 596 | ] 597 | } 598 | ], 599 | "source": [ 600 | "for i in range(10,1,-2):\n", 601 | " print(i,end=\" \")" 602 | ] 603 | }, 604 | { 605 | "cell_type": "code", 606 | "execution_count": 22, 607 | "metadata": {}, 608 | "outputs": [ 609 | { 610 | "name": "stdout", 611 | "output_type": "stream", 612 | "text": [ 613 | "enter no of rows3\n", 614 | "\n", 615 | "*\t\n", 616 | "*\t*\t\n", 617 | "*\t*\t*\t\n" 618 | ] 619 | } 620 | ], 621 | "source": [ 622 | "# *\n", 623 | "# * *\n", 624 | "# * * *\n", 625 | "n = int(input(\"enter no of rows\"))\n", 626 | "for i in range(n+1):\n", 627 | " for j in range(i):\n", 628 | " print(\"*\",end=\"\\t\")\n", 629 | " print() \n", 630 | " \n", 631 | " " 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": 1, 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "name": "stdout", 641 | "output_type": "stream", 642 | "text": [ 643 | "1\n", 644 | "2\n", 645 | "3\n", 646 | "4\n", 647 | "5\n", 648 | "6\n", 649 | "7\n", 650 | "8\n", 651 | "9\n", 652 | "10\n" 653 | ] 654 | } 655 | ], 656 | "source": [ 657 | "i = 1\n", 658 | "while i<=10:\n", 659 | " print(i)\n", 660 | " i+=1" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "execution_count": 2, 666 | "metadata": {}, 667 | "outputs": [ 668 | { 669 | "name": "stdout", 670 | "output_type": "stream", 671 | "text": [ 672 | "10\n", 673 | "9\n", 674 | "8\n", 675 | "7\n", 676 | "6\n", 677 | "5\n", 678 | "4\n", 679 | "3\n", 680 | "2\n", 681 | "1\n" 682 | ] 683 | } 684 | ], 685 | "source": [ 686 | "i=10\n", 687 | "while i>=1:\n", 688 | " print(i)\n", 689 | " i-=1" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": null, 695 | "metadata": {}, 696 | "outputs": [], 697 | "source": [ 698 | "# tasks\n", 699 | "# to convert celsius to fahrenhit and vice-versa\n", 700 | "# to convert rupees to euros and vice-versa\n", 701 | "# to print the average of 1 to 50\n", 702 | "# to print pascals triangle" 703 | ] 704 | } 705 | ], 706 | "metadata": { 707 | "kernelspec": { 708 | "display_name": "Python 3", 709 | "language": "python", 710 | "name": "python3" 711 | }, 712 | "language_info": { 713 | "codemirror_mode": { 714 | "name": "ipython", 715 | "version": 3 716 | }, 717 | "file_extension": ".py", 718 | "mimetype": "text/x-python", 719 | "name": "python", 720 | "nbconvert_exporter": "python", 721 | "pygments_lexer": "ipython3", 722 | "version": "3.7.3" 723 | } 724 | }, 725 | "nbformat": 4, 726 | "nbformat_minor": 2 727 | } 728 | -------------------------------------------------------------------------------- /24-06-2020.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Operators\n", 8 | "1. Arithmetic\n", 9 | "2. logical\n", 10 | "3. comparison\n", 11 | "4. identity\n", 12 | "5. membership\n", 13 | "6. assignment\n", 14 | "7. bitwise - &, |, ^" 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 | "2\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "a = 2\n", 32 | "b = 3\n", 33 | "print(a&b)\n", 34 | "# 0010\n", 35 | "# 8421 - 0+2+0+0=2 \n", 36 | "# 0011- 1+2+0+0=3 and\n", 37 | "# 0010" 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 | "3\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "print(a | b)\n", 55 | "# 0010\n", 56 | "# 0011\n", 57 | "# 0011" 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(a^b)" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "# Conditional statements\n", 82 | "## if \n", 83 | "## if - else\n", 84 | "## elif\n", 85 | "## Nested if" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "# elif syntax\n", 95 | "if condition:\n", 96 | " statements\n", 97 | "elif condition:\n", 98 | " statements\n", 99 | "else:\n", 100 | " statements" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 1, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "name": "stdout", 110 | "output_type": "stream", 111 | "text": [ 112 | "-9734\n", 113 | "negative\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "n = int(input())\n", 119 | "if n>0:\n", 120 | " print(\"positive\")\n", 121 | "elif n==0:\n", 122 | " print(\"zero\")\n", 123 | "else:\n", 124 | " print(\"negative\")" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 6, 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "1\n", 137 | "3\n", 138 | "45\n", 139 | "45 is large\n" 140 | ] 141 | } 142 | ], 143 | "source": [ 144 | "a = int(input())\n", 145 | "b = int(input())\n", 146 | "c = int(input())\n", 147 | "if a>b & a>c:\n", 148 | " print(a,\" is large\")\n", 149 | "elif b>c:\n", 150 | " print(b,\"is large\")\n", 151 | "else:\n", 152 | " print(c,\"is large\")" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 13, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "sdfghjkmm\n", 165 | "invalid username\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "username = \"apssdc\"\n", 171 | "password = 1234\n", 172 | "uname = input()\n", 173 | "if username == uname:\n", 174 | " pwd = int(input())\n", 175 | " if password == pwd:\n", 176 | " print(\"welcome \"+username)\n", 177 | " else:\n", 178 | " print(\"invalid password\")\n", 179 | "else:\n", 180 | " print(\"invalid username\")" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "# for loop syntax\n", 190 | "for i in range(start,stop,step):\n", 191 | " statements\n", 192 | "# range(stop+1)\n", 193 | "# range(start,stop)\n", 194 | "# range(start,stop,step) # 1,11,2" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 19, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "0 1 2 3 4 5 6 7 8 9 10 " 207 | ] 208 | } 209 | ], 210 | "source": [ 211 | "for i in range(10+1):\n", 212 | " print(i,end=\" \")" 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 24, 218 | "metadata": {}, 219 | "outputs": [ 220 | { 221 | "name": "stdout", 222 | "output_type": "stream", 223 | "text": [ 224 | "11\n", 225 | "13\n", 226 | "15\n", 227 | "17\n", 228 | "19\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "for i in range(11,21,2):\n", 234 | " print(i)" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 31, 240 | "metadata": {}, 241 | "outputs": [ 242 | { 243 | "name": "stdout", 244 | "output_type": "stream", 245 | "text": [ 246 | "no of rows5\n", 247 | "\n", 248 | "* \n", 249 | "* * \n", 250 | "* * * \n", 251 | "* * * * \n", 252 | "* * * * * \n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "#*\n", 258 | "#* *\n", 259 | "#* * *\n", 260 | "n=int(input(\"no of rows\"))\n", 261 | "for i in range(n+1):\n", 262 | " for j in range(i):\n", 263 | " print(\"*\",end = \" \")\n", 264 | " print()\n", 265 | " " 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 2, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "name": "stdout", 275 | "output_type": "stream", 276 | "text": [ 277 | "55\n" 278 | ] 279 | } 280 | ], 281 | "source": [ 282 | "i = 1\n", 283 | "s = 0\n", 284 | "while i<=10:\n", 285 | " s+=i\n", 286 | " i+=1\n", 287 | "print(s)\n", 288 | "()-paranthesis\n", 289 | "[]-brackets\n", 290 | "{}-braces" 291 | ] 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": 6, 296 | "metadata": {}, 297 | "outputs": [ 298 | { 299 | "name": "stdout", 300 | "output_type": "stream", 301 | "text": [ 302 | "10\n", 303 | "9\n", 304 | "8\n", 305 | "7\n", 306 | "6\n", 307 | "5\n", 308 | "4\n", 309 | "3\n", 310 | "2\n", 311 | "1\n" 312 | ] 313 | } 314 | ], 315 | "source": [ 316 | "i=10\n", 317 | "while (i>=1):\n", 318 | " print(i)\n", 319 | " i=i-1" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 5, 325 | "metadata": {}, 326 | "outputs": [ 327 | { 328 | "name": "stdout", 329 | "output_type": "stream", 330 | "text": [ 331 | "10\n", 332 | "7\n", 333 | "4\n", 334 | "1\n" 335 | ] 336 | } 337 | ], 338 | "source": [ 339 | "for i in range(10,0,-3):\n", 340 | " print(i)" 341 | ] 342 | }, 343 | { 344 | "cell_type": "code", 345 | "execution_count": null, 346 | "metadata": {}, 347 | "outputs": [], 348 | "source": [ 349 | "# Tasks\n", 350 | "# to print 1st and 2nd,3rd highest number\n", 351 | "# to convert celsius to fahrenhit and vice versa\n", 352 | "# to convert dollars to rupees and vice versa\n", 353 | "# to print pascals triangle\n" 354 | ] 355 | } 356 | ], 357 | "metadata": { 358 | "kernelspec": { 359 | "display_name": "Python 3", 360 | "language": "python", 361 | "name": "python3" 362 | }, 363 | "language_info": { 364 | "codemirror_mode": { 365 | "name": "ipython", 366 | "version": 3 367 | }, 368 | "file_extension": ".py", 369 | "mimetype": "text/x-python", 370 | "name": "python", 371 | "nbconvert_exporter": "python", 372 | "pygments_lexer": "ipython3", 373 | "version": "3.7.1" 374 | } 375 | }, 376 | "nbformat": 4, 377 | "nbformat_minor": 2 378 | } 379 | -------------------------------------------------------------------------------- /24th june.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Operators\n", 8 | "### Arithmetic - +,-,*,/,%,//,**\n", 9 | "### logical - and, or, not\n", 10 | "### Assignment - +=,-=,/=,*=,%=,//=,**=,=\n", 11 | "### bitwise - &,|,^,~,<<,>>\n", 12 | "### comparision - ==,!=,<=,>=,>,<\n", 13 | "### identity - is, is not\n", 14 | "### Membership - in , not in" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 5, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "2\n", 27 | "25\n" 28 | ] 29 | } 30 | ], 31 | "source": [ 32 | "a = 5\n", 33 | "b=2\n", 34 | "print(a//b)\n", 35 | "print(5**2)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 6, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "data": { 45 | "text/plain": [ 46 | "False" 47 | ] 48 | }, 49 | "execution_count": 6, 50 | "metadata": {}, 51 | "output_type": "execute_result" 52 | } 53 | ], 54 | "source": [ 55 | "2>5 and 4<5" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 8, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "False" 67 | ] 68 | }, 69 | "execution_count": 8, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "not(2>5 or 4<5)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 9, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#a = a+1\n", 85 | "a += 1" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 10, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "6" 97 | ] 98 | }, 99 | "execution_count": 10, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | } 103 | ], 104 | "source": [ 105 | "a" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 15, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "name": "stdout", 115 | "output_type": "stream", 116 | "text": [ 117 | "2\n", 118 | "3\n", 119 | "1\n", 120 | "-3\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "x = 2\n", 126 | "y = 3\n", 127 | "print(x&y)\n", 128 | "print(x|y)\n", 129 | "print(x^y)\n", 130 | "print(~x)\n", 131 | "# 0010\n", 132 | "# 0011\n", 133 | "# 0010" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 13, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "16" 145 | ] 146 | }, 147 | "execution_count": 13, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "x<>x\n", 176 | "# 0011\n", 177 | "# 0000" 178 | ] 179 | }, 180 | { 181 | "cell_type": "code", 182 | "execution_count": 16, 183 | "metadata": {}, 184 | "outputs": [ 185 | { 186 | "data": { 187 | "text/plain": [ 188 | "True" 189 | ] 190 | }, 191 | "execution_count": 16, 192 | "metadata": {}, 193 | "output_type": "execute_result" 194 | } 195 | ], 196 | "source": [ 197 | "\"hai\" < \"hi\"" 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": 17, 203 | "metadata": {}, 204 | "outputs": [ 205 | { 206 | "data": { 207 | "text/plain": [ 208 | "False" 209 | ] 210 | }, 211 | "execution_count": 17, 212 | "metadata": {}, 213 | "output_type": "execute_result" 214 | } 215 | ], 216 | "source": [ 217 | "\"a\" > \"k\"" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 19, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "data": { 227 | "text/plain": [ 228 | "True" 229 | ] 230 | }, 231 | "execution_count": 19, 232 | "metadata": {}, 233 | "output_type": "execute_result" 234 | } 235 | ], 236 | "source": [ 237 | "\"abc\" != \"ABC\"" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 20, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "data": { 247 | "text/plain": [ 248 | "True" 249 | ] 250 | }, 251 | "execution_count": 20, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "\"a\" is \"a\"" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 29, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "False\n" 270 | ] 271 | }, 272 | { 273 | "data": { 274 | "text/plain": [ 275 | "True" 276 | ] 277 | }, 278 | "execution_count": 29, 279 | "metadata": {}, 280 | "output_type": "execute_result" 281 | } 282 | ], 283 | "source": [ 284 | "print(5 is 55)\n", 285 | "5 is not 55" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 27, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "data": { 295 | "text/plain": [ 296 | "True" 297 | ] 298 | }, 299 | "execution_count": 27, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "a = 3\n", 306 | "b = 3\n", 307 | "c = 78\n", 308 | "a is b" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 24, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "140727498355600" 320 | ] 321 | }, 322 | "execution_count": 24, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "id(a)" 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 28, 334 | "metadata": {}, 335 | "outputs": [ 336 | { 337 | "data": { 338 | "text/plain": [ 339 | "140727498358000" 340 | ] 341 | }, 342 | "execution_count": 28, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "id(c)" 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "execution_count": 30, 354 | "metadata": {}, 355 | "outputs": [ 356 | { 357 | "data": { 358 | "text/plain": [ 359 | "True" 360 | ] 361 | }, 362 | "execution_count": 30, 363 | "metadata": {}, 364 | "output_type": "execute_result" 365 | } 366 | ], 367 | "source": [ 368 | "\"A\" in \"apssdcA\"" 369 | ] 370 | }, 371 | { 372 | "cell_type": "code", 373 | "execution_count": 31, 374 | "metadata": {}, 375 | "outputs": [ 376 | { 377 | "data": { 378 | "text/plain": [ 379 | "True" 380 | ] 381 | }, 382 | "execution_count": 31, 383 | "metadata": {}, 384 | "output_type": "execute_result" 385 | } 386 | ], 387 | "source": [ 388 | "l = [1,2,3,4,5]\n", 389 | "5 in l" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": 33, 395 | "metadata": {}, 396 | "outputs": [ 397 | { 398 | "data": { 399 | "text/plain": [ 400 | "False" 401 | ] 402 | }, 403 | "execution_count": 33, 404 | "metadata": {}, 405 | "output_type": "execute_result" 406 | } 407 | ], 408 | "source": [ 409 | "s = \"python\"\n", 410 | "\"o\" not in s" 411 | ] 412 | }, 413 | { 414 | "cell_type": "markdown", 415 | "metadata": {}, 416 | "source": [ 417 | "# Conditional Statements\n", 418 | "#### if\n", 419 | "#### if-else\n", 420 | "#### elif\n", 421 | "#### nested if" 422 | ] 423 | }, 424 | { 425 | "cell_type": "code", 426 | "execution_count": null, 427 | "metadata": {}, 428 | "outputs": [], 429 | "source": [ 430 | "# elif syntax\n", 431 | "if condition:\n", 432 | " statements\n", 433 | "elif condition:\n", 434 | " statements\n", 435 | "else:\n", 436 | " statements" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 1, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "name": "stdout", 446 | "output_type": "stream", 447 | "text": [ 448 | "enter n3\n", 449 | "positive\n" 450 | ] 451 | } 452 | ], 453 | "source": [ 454 | "n = int(input(\"enter n\"))\n", 455 | "if n>0:\n", 456 | " print(\"positive\")\n", 457 | "elif n<0:\n", 458 | " print(\"negative\")\n", 459 | "else:\n", 460 | " print(\"zero\")" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 5, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "name": "stdout", 470 | "output_type": "stream", 471 | "text": [ 472 | "2\n", 473 | "3\n", 474 | "6\n", 475 | "6 is large\n" 476 | ] 477 | } 478 | ], 479 | "source": [ 480 | "a = int(input(\"enter a \"))\n", 481 | "b = int(input(\"enter b\"))\n", 482 | "c = int(input(\"enter c\"))\n", 483 | "if a>b and a>c:\n", 484 | " print(a,\"is large\")\n", 485 | "elif b>c:\n", 486 | " print(b,\"is large\")\n", 487 | "else:\n", 488 | " print(c,\"is large\")" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": 7, 494 | "metadata": {}, 495 | "outputs": [ 496 | { 497 | "name": "stdout", 498 | "output_type": "stream", 499 | "text": [ 500 | "enter usernamesdfghjnm\n", 501 | "enter passowrdxcvbnm,\n", 502 | "invalid username or password\n" 503 | ] 504 | } 505 | ], 506 | "source": [ 507 | "uname = \"apssdc\"\n", 508 | "pwd = \"1234\"\n", 509 | "username = input(\"enter username\")\n", 510 | "password = input(\"enter passowrd\")\n", 511 | "if uname == username and pwd == password:\n", 512 | " print(\"welcome \"+username+\" for login\")\n", 513 | "else:\n", 514 | " print(\"invalid username or password\")\n", 515 | " " 516 | ] 517 | }, 518 | { 519 | "cell_type": "code", 520 | "execution_count": null, 521 | "metadata": {}, 522 | "outputs": [], 523 | "source": [ 524 | "# for loop syntax\n", 525 | "for i in range(start,stop,step):\n", 526 | " statements\n", 527 | "# range(stop)\n", 528 | "# range(start,stop)\n", 529 | "# range(start,stop,step)" 530 | ] 531 | }, 532 | { 533 | "cell_type": "code", 534 | "execution_count": 9, 535 | "metadata": {}, 536 | "outputs": [ 537 | { 538 | "name": "stdout", 539 | "output_type": "stream", 540 | "text": [ 541 | "0\n", 542 | "1\n", 543 | "2\n", 544 | "3\n", 545 | "4\n", 546 | "5\n", 547 | "6\n", 548 | "7\n", 549 | "8\n", 550 | "9\n", 551 | "10\n" 552 | ] 553 | } 554 | ], 555 | "source": [ 556 | "for i in range(10+1):\n", 557 | " print(i)" 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "execution_count": 14, 563 | "metadata": {}, 564 | "outputs": [ 565 | { 566 | "name": "stdout", 567 | "output_type": "stream", 568 | "text": [ 569 | "11\n", 570 | "\n", 571 | "14\n", 572 | "\n", 573 | "17\n", 574 | "\n", 575 | "20\n", 576 | "\n" 577 | ] 578 | } 579 | ], 580 | "source": [ 581 | "for i in range(11,21,3):\n", 582 | " print(i)\n", 583 | " print()" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 13, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "name": "stdout", 593 | "output_type": "stream", 594 | "text": [ 595 | "10 8 6 4 2 " 596 | ] 597 | } 598 | ], 599 | "source": [ 600 | "for i in range(10,1,-2):\n", 601 | " print(i,end=\" \")" 602 | ] 603 | }, 604 | { 605 | "cell_type": "code", 606 | "execution_count": 22, 607 | "metadata": {}, 608 | "outputs": [ 609 | { 610 | "name": "stdout", 611 | "output_type": "stream", 612 | "text": [ 613 | "enter no of rows3\n", 614 | "\n", 615 | "*\t\n", 616 | "*\t*\t\n", 617 | "*\t*\t*\t\n" 618 | ] 619 | } 620 | ], 621 | "source": [ 622 | "# *\n", 623 | "# * *\n", 624 | "# * * *\n", 625 | "n = int(input(\"enter no of rows\"))\n", 626 | "for i in range(n+1):\n", 627 | " for j in range(i):\n", 628 | " print(\"*\",end=\"\\t\")\n", 629 | " print() \n", 630 | " \n", 631 | " " 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": 1, 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "name": "stdout", 641 | "output_type": "stream", 642 | "text": [ 643 | "1\n", 644 | "2\n", 645 | "3\n", 646 | "4\n", 647 | "5\n", 648 | "6\n", 649 | "7\n", 650 | "8\n", 651 | "9\n", 652 | "10\n" 653 | ] 654 | } 655 | ], 656 | "source": [ 657 | "i = 1\n", 658 | "while i<=10:\n", 659 | " print(i)\n", 660 | " i+=1" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "execution_count": 2, 666 | "metadata": {}, 667 | "outputs": [ 668 | { 669 | "name": "stdout", 670 | "output_type": "stream", 671 | "text": [ 672 | "10\n", 673 | "9\n", 674 | "8\n", 675 | "7\n", 676 | "6\n", 677 | "5\n", 678 | "4\n", 679 | "3\n", 680 | "2\n", 681 | "1\n" 682 | ] 683 | } 684 | ], 685 | "source": [ 686 | "i=10\n", 687 | "while i>=1:\n", 688 | " print(i)\n", 689 | " i-=1" 690 | ] 691 | }, 692 | { 693 | "cell_type": "code", 694 | "execution_count": null, 695 | "metadata": {}, 696 | "outputs": [], 697 | "source": [ 698 | "# tasks\n", 699 | "# to convert celsius to fahrenhit and vice-versa\n", 700 | "# to convert rupees to euros and vice-versa\n", 701 | "# to print the average of 1 to 50\n", 702 | "# to print pascals triangle" 703 | ] 704 | } 705 | ], 706 | "metadata": { 707 | "kernelspec": { 708 | "display_name": "Python 3", 709 | "language": "python", 710 | "name": "python3" 711 | }, 712 | "language_info": { 713 | "codemirror_mode": { 714 | "name": "ipython", 715 | "version": 3 716 | }, 717 | "file_extension": ".py", 718 | "mimetype": "text/x-python", 719 | "name": "python", 720 | "nbconvert_exporter": "python", 721 | "pygments_lexer": "ipython3", 722 | "version": "3.7.1" 723 | } 724 | }, 725 | "nbformat": 4, 726 | "nbformat_minor": 2 727 | } 728 | -------------------------------------------------------------------------------- /25-06-2020(Day-4).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Loop Statements\n" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### jump statements\n", 15 | "- 1. break \n", 16 | "- 2. continue\n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 2, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "value is matched\n", 29 | "found at 2 location\n" 30 | ] 31 | } 32 | ], 33 | "source": [ 34 | "list = [1,2,3,4]\n", 35 | "count = 1\n", 36 | "for i in list:\n", 37 | " if i == 4:\n", 38 | " print(\"value is matched\")\n", 39 | " count = count+1\n", 40 | " break\n", 41 | "print(\"found at\",count,\"location\")" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 4, 47 | "metadata": {}, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "p\n", 54 | "y\n", 55 | "t\n", 56 | "h\n" 57 | ] 58 | } 59 | ], 60 | "source": [ 61 | "str = \"python\"\n", 62 | "for i in str:\n", 63 | " if i== 'o':\n", 64 | " break\n", 65 | " print(i)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## continue\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 7, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdout", 82 | "output_type": "stream", 83 | "text": [ 84 | "1\n", 85 | "2\n", 86 | "3\n", 87 | "4\n", 88 | "6\n", 89 | "7\n", 90 | "8\n", 91 | "9\n", 92 | "10\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "i=0\n", 98 | "while(i<10):\n", 99 | " i=i+1 # i=0+1=1,i=1+1=2,\n", 100 | " if(i==5):\n", 101 | " continue\n", 102 | " print(i)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 9, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "a\n", 115 | "s\n", 116 | "s\n", 117 | "d\n", 118 | "c\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "str=\"apssdc\"\n", 124 | "for i in str:\n", 125 | " if(i=='p'):\n", 126 | " continue\n", 127 | " print(i)" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "# String\n", 135 | "- string is a group of characters\n", 136 | "- enclosed with a single quotes same as double quotes\n" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 12, 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "\n", 149 | "welcome\n" 150 | ] 151 | } 152 | ], 153 | "source": [ 154 | "s = \"welcome\"\n", 155 | "print(type(s))\n", 156 | "print(s)" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 17, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "name": "stdout", 166 | "output_type": "stream", 167 | "text": [ 168 | "w\n" 169 | ] 170 | } 171 | ], 172 | "source": [ 173 | "s = \"welcome\"\n", 174 | "print(s[-7])" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 14, 180 | "metadata": {}, 181 | "outputs": [ 182 | { 183 | "data": { 184 | "text/plain": [ 185 | "'c'" 186 | ] 187 | }, 188 | "execution_count": 14, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "s[3]" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 15, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "'come'" 206 | ] 207 | }, 208 | "execution_count": 15, 209 | "metadata": {}, 210 | "output_type": "execute_result" 211 | } 212 | ], 213 | "source": [ 214 | "s[3:]" 215 | ] 216 | }, 217 | { 218 | "cell_type": "code", 219 | "execution_count": 16, 220 | "metadata": {}, 221 | "outputs": [ 222 | { 223 | "data": { 224 | "text/plain": [ 225 | "'eve'" 226 | ] 227 | }, 228 | "execution_count": 16, 229 | "metadata": {}, 230 | "output_type": "execute_result" 231 | } 232 | ], 233 | "source": [ 234 | "st=\"hai everyone\"\n", 235 | "st[4:7]" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": 18, 241 | "metadata": {}, 242 | "outputs": [ 243 | { 244 | "data": { 245 | "text/plain": [ 246 | "'welcome'" 247 | ] 248 | }, 249 | "execution_count": 18, 250 | "metadata": {}, 251 | "output_type": "execute_result" 252 | } 253 | ], 254 | "source": [ 255 | "s" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 22, 261 | "metadata": {}, 262 | "outputs": [ 263 | { 264 | "data": { 265 | "text/plain": [ 266 | "'emoclew'" 267 | ] 268 | }, 269 | "execution_count": 22, 270 | "metadata": {}, 271 | "output_type": "execute_result" 272 | } 273 | ], 274 | "source": [ 275 | "s[::-1]" 276 | ] 277 | }, 278 | { 279 | "cell_type": "code", 280 | "execution_count": 23, 281 | "metadata": {}, 282 | "outputs": [ 283 | { 284 | "data": { 285 | "text/plain": [ 286 | "'welcome'" 287 | ] 288 | }, 289 | "execution_count": 23, 290 | "metadata": {}, 291 | "output_type": "execute_result" 292 | } 293 | ], 294 | "source": [ 295 | "s.lower()" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 24, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/plain": [ 306 | "'WELCOME'" 307 | ] 308 | }, 309 | "execution_count": 24, 310 | "metadata": {}, 311 | "output_type": "execute_result" 312 | } 313 | ], 314 | "source": [ 315 | "s.upper()" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 25, 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "data": { 325 | "text/plain": [ 326 | "'Welcome'" 327 | ] 328 | }, 329 | "execution_count": 25, 330 | "metadata": {}, 331 | "output_type": "execute_result" 332 | } 333 | ], 334 | "source": [ 335 | "s.capitalize()" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 26, 341 | "metadata": {}, 342 | "outputs": [ 343 | { 344 | "data": { 345 | "text/plain": [ 346 | "'webcome'" 347 | ] 348 | }, 349 | "execution_count": 26, 350 | "metadata": {}, 351 | "output_type": "execute_result" 352 | } 353 | ], 354 | "source": [ 355 | "s.replace('l','b')" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 28, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "data": { 365 | "text/plain": [ 366 | "['hai', 'everyone']" 367 | ] 368 | }, 369 | "execution_count": 28, 370 | "metadata": {}, 371 | "output_type": "execute_result" 372 | } 373 | ], 374 | "source": [ 375 | "st.split()" 376 | ] 377 | }, 378 | { 379 | "cell_type": "code", 380 | "execution_count": 29, 381 | "metadata": {}, 382 | "outputs": [ 383 | { 384 | "data": { 385 | "text/plain": [ 386 | "'w_e_l_c_o_m_e'" 387 | ] 388 | }, 389 | "execution_count": 29, 390 | "metadata": {}, 391 | "output_type": "execute_result" 392 | } 393 | ], 394 | "source": [ 395 | "s1='_'\n", 396 | "s1.join(s)" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 30, 402 | "metadata": {}, 403 | "outputs": [ 404 | { 405 | "data": { 406 | "text/plain": [ 407 | "0" 408 | ] 409 | }, 410 | "execution_count": 30, 411 | "metadata": {}, 412 | "output_type": "execute_result" 413 | } 414 | ], 415 | "source": [ 416 | "st.find('hai')" 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "execution_count": 31, 422 | "metadata": {}, 423 | "outputs": [ 424 | { 425 | "data": { 426 | "text/plain": [ 427 | "1" 428 | ] 429 | }, 430 | "execution_count": 31, 431 | "metadata": {}, 432 | "output_type": "execute_result" 433 | } 434 | ], 435 | "source": [ 436 | "s.find('e')" 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 32, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "data": { 446 | "text/plain": [ 447 | "7" 448 | ] 449 | }, 450 | "execution_count": 32, 451 | "metadata": {}, 452 | "output_type": "execute_result" 453 | } 454 | ], 455 | "source": [ 456 | "len(s)" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 33, 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "data": { 466 | "text/plain": [ 467 | "12" 468 | ] 469 | }, 470 | "execution_count": 33, 471 | "metadata": {}, 472 | "output_type": "execute_result" 473 | } 474 | ], 475 | "source": [ 476 | "len(st)" 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 34, 482 | "metadata": {}, 483 | "outputs": [ 484 | { 485 | "data": { 486 | "text/plain": [ 487 | "'welcomehai everyone'" 488 | ] 489 | }, 490 | "execution_count": 34, 491 | "metadata": {}, 492 | "output_type": "execute_result" 493 | } 494 | ], 495 | "source": [ 496 | "s+st" 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": 37, 502 | "metadata": {}, 503 | "outputs": [ 504 | { 505 | "data": { 506 | "text/plain": [ 507 | "'12ap'" 508 | ] 509 | }, 510 | "execution_count": 37, 511 | "metadata": {}, 512 | "output_type": "execute_result" 513 | } 514 | ], 515 | "source": [ 516 | "s2=\"12\"\n", 517 | "s3=\"ap\"\n", 518 | "s2+s3" 519 | ] 520 | }, 521 | { 522 | "cell_type": "code", 523 | "execution_count": 38, 524 | "metadata": {}, 525 | "outputs": [ 526 | { 527 | "data": { 528 | "text/plain": [ 529 | "'1212121212'" 530 | ] 531 | }, 532 | "execution_count": 38, 533 | "metadata": {}, 534 | "output_type": "execute_result" 535 | } 536 | ], 537 | "source": [ 538 | "s2*5" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 1, 544 | "metadata": {}, 545 | "outputs": [ 546 | { 547 | "name": "stdout", 548 | "output_type": "stream", 549 | "text": [ 550 | "p\n" 551 | ] 552 | } 553 | ], 554 | "source": [ 555 | "fruit =\"apple\"\n", 556 | "letter=fruit[1]\n", 557 | "print(letter)" 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "execution_count": 5, 563 | "metadata": {}, 564 | "outputs": [ 565 | { 566 | "name": "stdout", 567 | "output_type": "stream", 568 | "text": [ 569 | "palindrome\n" 570 | ] 571 | } 572 | ], 573 | "source": [ 574 | "# write a pgm to given string palindrome or not\n", 575 | "s1=\"welcome\"\n", 576 | "s2=\"RACECAR\"\n", 577 | "if s2==s2[::-1]:\n", 578 | " print(\"palindrome\")\n", 579 | "else:\n", 580 | " print(\"not\")\n" 581 | ] 582 | }, 583 | { 584 | "cell_type": "code", 585 | "execution_count": 2, 586 | "metadata": {}, 587 | "outputs": [ 588 | { 589 | "data": { 590 | "text/plain": [ 591 | "True" 592 | ] 593 | }, 594 | "execution_count": 2, 595 | "metadata": {}, 596 | "output_type": "execute_result" 597 | } 598 | ], 599 | "source": [ 600 | "'a' in 'program'" 601 | ] 602 | }, 603 | { 604 | "cell_type": "code", 605 | "execution_count": 3, 606 | "metadata": {}, 607 | "outputs": [ 608 | { 609 | "data": { 610 | "text/plain": [ 611 | "False" 612 | ] 613 | }, 614 | "execution_count": 3, 615 | "metadata": {}, 616 | "output_type": "execute_result" 617 | } 618 | ], 619 | "source": [ 620 | "'a' not in 'program'" 621 | ] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "execution_count": 6, 626 | "metadata": {}, 627 | "outputs": [ 628 | { 629 | "data": { 630 | "text/plain": [ 631 | "'welcome'" 632 | ] 633 | }, 634 | "execution_count": 6, 635 | "metadata": {}, 636 | "output_type": "execute_result" 637 | } 638 | ], 639 | "source": [ 640 | "s1.replace('python','apssdc')" 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": 41, 646 | "metadata": {}, 647 | "outputs": [ 648 | { 649 | "data": { 650 | "text/plain": [ 651 | "'hai everyone'" 652 | ] 653 | }, 654 | "execution_count": 41, 655 | "metadata": {}, 656 | "output_type": "execute_result" 657 | } 658 | ], 659 | "source": [ 660 | "st" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "execution_count": 42, 666 | "metadata": {}, 667 | "outputs": [], 668 | "source": [ 669 | "del st" 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "execution_count": 43, 675 | "metadata": {}, 676 | "outputs": [ 677 | { 678 | "ename": "NameError", 679 | "evalue": "name 'st' is not defined", 680 | "output_type": "error", 681 | "traceback": [ 682 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 683 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 684 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mst\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 685 | "\u001b[1;31mNameError\u001b[0m: name 'st' is not defined" 686 | ] 687 | } 688 | ], 689 | "source": [ 690 | "st" 691 | ] 692 | }, 693 | { 694 | "cell_type": "code", 695 | "execution_count": 46, 696 | "metadata": {}, 697 | "outputs": [ 698 | { 699 | "name": "stdout", 700 | "output_type": "stream", 701 | "text": [ 702 | "welcome to python\n" 703 | ] 704 | } 705 | ], 706 | "source": [ 707 | "s = \" welcome to python \"\n", 708 | "print(s.strip())" 709 | ] 710 | }, 711 | { 712 | "cell_type": "code", 713 | "execution_count": 47, 714 | "metadata": {}, 715 | "outputs": [ 716 | { 717 | "name": "stdout", 718 | "output_type": "stream", 719 | "text": [ 720 | " welcome to python\n" 721 | ] 722 | } 723 | ], 724 | "source": [ 725 | "print(s.rstrip())" 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": 48, 731 | "metadata": {}, 732 | "outputs": [ 733 | { 734 | "name": "stdout", 735 | "output_type": "stream", 736 | "text": [ 737 | "welcome to python \n" 738 | ] 739 | } 740 | ], 741 | "source": [ 742 | "print(s.lstrip())" 743 | ] 744 | }, 745 | { 746 | "cell_type": "code", 747 | "execution_count": 49, 748 | "metadata": {}, 749 | "outputs": [ 750 | { 751 | "name": "stdout", 752 | "output_type": "stream", 753 | "text": [ 754 | "Welcome To Python\n" 755 | ] 756 | } 757 | ], 758 | "source": [ 759 | "s = \"welcome to python\"\n", 760 | "print(s.title())" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": null, 766 | "metadata": {}, 767 | "outputs": [], 768 | "source": [ 769 | "# Task\n", 770 | "#input : abc3h5h67\n", 771 | "# output : 21(3+5+6+7)" 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "execution_count": 7, 777 | "metadata": {}, 778 | "outputs": [ 779 | { 780 | "data": { 781 | "text/plain": [ 782 | "'hai to hello'" 783 | ] 784 | }, 785 | "execution_count": 7, 786 | "metadata": {}, 787 | "output_type": "execute_result" 788 | } 789 | ], 790 | "source": [ 791 | "st=\"hai to everyone\"\n", 792 | "st[:6]+\" hello\"" 793 | ] 794 | }, 795 | { 796 | "cell_type": "code", 797 | "execution_count": 8, 798 | "metadata": {}, 799 | "outputs": [ 800 | { 801 | "name": "stdout", 802 | "output_type": "stream", 803 | "text": [ 804 | "HELLO EVERYONE\n" 805 | ] 806 | } 807 | ], 808 | "source": [ 809 | "swap=\"hello everyone\"\n", 810 | "x=swap.swapcase()\n", 811 | "print(x)" 812 | ] 813 | }, 814 | { 815 | "cell_type": "code", 816 | "execution_count": 9, 817 | "metadata": {}, 818 | "outputs": [ 819 | { 820 | "name": "stdout", 821 | "output_type": "stream", 822 | "text": [ 823 | "False\n" 824 | ] 825 | } 826 | ], 827 | "source": [ 828 | "string = \"123saresf65\"\n", 829 | "print(string.isnumeric())" 830 | ] 831 | }, 832 | { 833 | "cell_type": "code", 834 | "execution_count": 10, 835 | "metadata": {}, 836 | "outputs": [ 837 | { 838 | "name": "stdout", 839 | "output_type": "stream", 840 | "text": [ 841 | "True\n" 842 | ] 843 | } 844 | ], 845 | "source": [ 846 | "string = \"12365\"\n", 847 | "print(string.isnumeric())" 848 | ] 849 | }, 850 | { 851 | "cell_type": "code", 852 | "execution_count": 11, 853 | "metadata": {}, 854 | "outputs": [ 855 | { 856 | "data": { 857 | "text/plain": [ 858 | "'welcome'" 859 | ] 860 | }, 861 | "execution_count": 11, 862 | "metadata": {}, 863 | "output_type": "execute_result" 864 | } 865 | ], 866 | "source": [ 867 | "st=\" welcome \"\n", 868 | "st.strip()" 869 | ] 870 | }, 871 | { 872 | "cell_type": "code", 873 | "execution_count": 12, 874 | "metadata": {}, 875 | "outputs": [ 876 | { 877 | "data": { 878 | "text/plain": [ 879 | "'welcome '" 880 | ] 881 | }, 882 | "execution_count": 12, 883 | "metadata": {}, 884 | "output_type": "execute_result" 885 | } 886 | ], 887 | "source": [ 888 | "st.lstrip()" 889 | ] 890 | }, 891 | { 892 | "cell_type": "code", 893 | "execution_count": 13, 894 | "metadata": {}, 895 | "outputs": [ 896 | { 897 | "data": { 898 | "text/plain": [ 899 | "' welcome'" 900 | ] 901 | }, 902 | "execution_count": 13, 903 | "metadata": {}, 904 | "output_type": "execute_result" 905 | } 906 | ], 907 | "source": [ 908 | "st.rstrip()" 909 | ] 910 | }, 911 | { 912 | "cell_type": "code", 913 | "execution_count": 14, 914 | "metadata": {}, 915 | "outputs": [ 916 | { 917 | "name": "stdout", 918 | "output_type": "stream", 919 | "text": [ 920 | "enter stringabc123#@*\n", 921 | "alpha 3,digits 3, special char 3\n" 922 | ] 923 | } 924 | ], 925 | "source": [ 926 | "# input :\"abc123#@*\"\n", 927 | "# output : alpha-3, digits-3,special char-3\n", 928 | "s= input(\"enter string\")\n", 929 | "abc=dc=scc=0# intially all are 0\n", 930 | "for i in s:\n", 931 | " if i.isalpha():\n", 932 | " abc+=1\n", 933 | " elif i.isdigit():\n", 934 | " dc+=1\n", 935 | " else:\n", 936 | " scc+=1\n", 937 | "print('alpha {},digits {}, special char {}'.format(abc,dc,scc))" 938 | ] 939 | }, 940 | { 941 | "cell_type": "code", 942 | "execution_count": 18, 943 | "metadata": {}, 944 | "outputs": [ 945 | { 946 | "name": "stdout", 947 | "output_type": "stream", 948 | "text": [ 949 | "enter a stringaPsSdC\n", 950 | "ApSsDc\n" 951 | ] 952 | } 953 | ], 954 | "source": [ 955 | "# Task\n", 956 | "# input = \"aPsSdC\"\n", 957 | "# output = \"ApSsDc\"\n", 958 | "x=input(\"enter a string\")\n", 959 | "y=x.swapcase()\n", 960 | "print(y)" 961 | ] 962 | }, 963 | { 964 | "cell_type": "code", 965 | "execution_count": 16, 966 | "metadata": {}, 967 | "outputs": [ 968 | { 969 | "name": "stdout", 970 | "output_type": "stream", 971 | "text": [ 972 | "enter stringsudha\n", 973 | "s*d*a\n" 974 | ] 975 | } 976 | ], 977 | "source": [ 978 | "s=input(\"enter string\")\n", 979 | "s1=''\n", 980 | "for i in range(len(s)):\n", 981 | " if i%2!=0:\n", 982 | " s1+=s[i].replace(s[i],\"*\")\n", 983 | " else:\n", 984 | " s1+=s[i].replace(s[i],s[i])\n", 985 | "print(s1)" 986 | ] 987 | }, 988 | { 989 | "cell_type": "code", 990 | "execution_count": 17, 991 | "metadata": {}, 992 | "outputs": [ 993 | { 994 | "name": "stdout", 995 | "output_type": "stream", 996 | "text": [ 997 | "enter stringabcabc\n", 998 | "a:2 b:2 c:2 " 999 | ] 1000 | } 1001 | ], 1002 | "source": [ 1003 | "# print a characters count\n", 1004 | "# input = abcabc\n", 1005 | "# output = a:2,b:2,c:2\n", 1006 | "s=input(\"enter string\")\n", 1007 | "s1=''\n", 1008 | "for i in s:\n", 1009 | " if i not in s1:\n", 1010 | " print('{}:{}'.format(i,s.count(i)),end=' ')\n", 1011 | " s1+=i" 1012 | ] 1013 | }, 1014 | { 1015 | "cell_type": "code", 1016 | "execution_count": null, 1017 | "metadata": {}, 1018 | "outputs": [], 1019 | "source": [] 1020 | } 1021 | ], 1022 | "metadata": { 1023 | "kernelspec": { 1024 | "display_name": "Python 3", 1025 | "language": "python", 1026 | "name": "python3" 1027 | }, 1028 | "language_info": { 1029 | "codemirror_mode": { 1030 | "name": "ipython", 1031 | "version": 3 1032 | }, 1033 | "file_extension": ".py", 1034 | "mimetype": "text/x-python", 1035 | "name": "python", 1036 | "nbconvert_exporter": "python", 1037 | "pygments_lexer": "ipython3", 1038 | "version": "3.7.3" 1039 | } 1040 | }, 1041 | "nbformat": 4, 1042 | "nbformat_minor": 4 1043 | } 1044 | -------------------------------------------------------------------------------- /27-06-2020(DAY-6).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "# datastructures:\n", 10 | "- datastructures are a way of organizing and storing data." 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "metadata": {}, 17 | "outputs": [], 18 | "source": [ 19 | "#we have 4 types of datastructures in python:\n", 20 | "1.list\n", 21 | "2.tuple\n", 22 | "3.dictionary\n", 23 | "4.sets" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "# lists" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "- list is a datastructure that holds an ordered collection of items.\n", 40 | "- allows duplicates\n", 41 | "- you can recognize lists by their square brackets []\n", 42 | "- list is mutable,which means that you can change their content without chnaging their identity" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 1, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "[]\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# empty list\n", 60 | "li=[]\n", 61 | "print(li)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 2, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stdout", 71 | "output_type": "stream", 72 | "text": [ 73 | "[12, 67.89, 'python']\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "li=[12,67.89,'python'] #all datatypes\n", 79 | "print(li)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 8, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "[12, 12, 12, 1, 4, 90, 70, 12]\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "li=[12,12,12,1,4,90,70,12]#duplicates,unordered\n", 97 | "print(li)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 11, 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "\n", 110 | "8\n", 111 | "213\n", 112 | "1\n", 113 | "90\n", 114 | "[1, 4, 12, 12, 12, 12, 70, 90]\n" 115 | ] 116 | } 117 | ], 118 | "source": [ 119 | "print(type(li))\n", 120 | "print(len(li))\n", 121 | "print(sum(li))\n", 122 | "print(min(li))\n", 123 | "print(max(li))\n", 124 | "print(sorted(li))" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 22, 130 | "metadata": {}, 131 | "outputs": [ 132 | { 133 | "name": "stdout", 134 | "output_type": "stream", 135 | "text": [ 136 | "True\n", 137 | "True\n", 138 | "False\n", 139 | "True\n", 140 | "[(0, 'pavani'), (1, 'ambika'), (2, 'poojitha')]\n", 141 | "[]\n", 142 | "[('pavani', 10), ('ambika', 20), ('poojitha', 50)]\n", 143 | "[]\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "number=[]\n", 149 | "names=['pavani','ambika','poojitha']\n", 150 | "rollno=[10,20,50,80,11]\n", 151 | "print(all(number))#list\n", 152 | "print(all(names))\n", 153 | "print(any(number)) #values\n", 154 | "print(any(names))\n", 155 | "print(list(enumerate(names)))\n", 156 | "print(list(enumerate(number)))\n", 157 | "print(list(zip(names,rollno)))\n", 158 | "print(list(zip(names,number)))" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 30, 164 | "metadata": {}, 165 | "outputs": [ 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "45\n", 171 | "34\n", 172 | "[34, 12, 45]\n", 173 | "[24, 12, 10]\n", 174 | "[10, 45, 12, 34, 24]\n" 175 | ] 176 | } 177 | ], 178 | "source": [ 179 | "#accessing list elements\n", 180 | "li=[24,34,12,45,10] #list supports indexing and slicing\n", 181 | "#indexing\n", 182 | "print(li[3])\n", 183 | "#negtive indexing\n", 184 | "print(li[-4])\n", 185 | "#slicing\n", 186 | "print(li[1:4]) #[start:end+1] \n", 187 | "print(li[::2])\n", 188 | "print(li[::-1])" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": 31, 194 | "metadata": {}, 195 | "outputs": [ 196 | { 197 | "name": "stdout", 198 | "output_type": "stream", 199 | "text": [ 200 | "[12, 10, 30, 11, 1, 23, 12, 10, 5, 4, 89]\n" 201 | ] 202 | } 203 | ], 204 | "source": [ 205 | "#concatenation\n", 206 | "l1=[12,10,30,11,1]\n", 207 | "l2=[23,12,10,5,4,89]\n", 208 | "print(l1+l2)" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 38, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "[10, 20, 30, 14, [56, 77, 15], 90]\n", 221 | "\n", 222 | "30\n", 223 | "[56, 77, 15]\n", 224 | "77\n" 225 | ] 226 | }, 227 | { 228 | "ename": "TypeError", 229 | "evalue": "'<' not supported between instances of 'list' and 'int'", 230 | "output_type": "error", 231 | "traceback": [ 232 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 233 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 234 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ml\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ml\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msorted\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 235 | "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'list' and 'int'" 236 | ] 237 | } 238 | ], 239 | "source": [ 240 | "# nested list\n", 241 | "l=[10,20,30,14,[56,77,15],90]\n", 242 | "print(l)\n", 243 | "print(type(l))\n", 244 | "print(l[2])\n", 245 | "print(l[4])\n", 246 | "print(l[4][1])\n", 247 | "print(sorted(l))" 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": 37, 253 | "metadata": {}, 254 | "outputs": [ 255 | { 256 | "name": "stdout", 257 | "output_type": "stream", 258 | "text": [ 259 | "[10, 20, 30, 14, 88, 90]\n" 260 | ] 261 | } 262 | ], 263 | "source": [ 264 | "l[4]=88 # list is mutable\n", 265 | "print(l)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 40, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "name": "stdout", 275 | "output_type": "stream", 276 | "text": [ 277 | "['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] " 278 | ] 279 | } 280 | ], 281 | "source": [ 282 | "print(dir(list),end=\" \")" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 44, 288 | "metadata": {}, 289 | "outputs": [ 290 | { 291 | "name": "stdout", 292 | "output_type": "stream", 293 | "text": [ 294 | "[23, 1, 2, 12, 1, 56, 90, 20, 20, 20, 20, 20, 100]\n" 295 | ] 296 | } 297 | ], 298 | "source": [ 299 | "li=[23,1,2,12,1,56,90,20,20,20,20,20]\n", 300 | "li.append(100) #end of the list -->value\n", 301 | "print(li)" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 45, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "[23, 1, 2, 77, 12, 1, 56, 90, 20, 20, 20, 20, 20, 100]\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "li.insert(3,77) #index,value\n", 319 | "print(li)" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 47, 325 | "metadata": {}, 326 | "outputs": [ 327 | { 328 | "data": { 329 | "text/plain": [ 330 | "5" 331 | ] 332 | }, 333 | "execution_count": 47, 334 | "metadata": {}, 335 | "output_type": "execute_result" 336 | } 337 | ], 338 | "source": [ 339 | "li.count(20)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 48, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "8" 351 | ] 352 | }, 353 | "execution_count": 48, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "li.index(20)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 52, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "[1, 2, 77, 12, 1, 56, 90, 20, 20, 20, 20]" 371 | ] 372 | }, 373 | "execution_count": 52, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "li.remove(20) #value\n", 380 | "li" 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 50, 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "name": "stdout", 390 | "output_type": "stream", 391 | "text": [ 392 | "[1, 2, 77, 12, 1, 56, 90, 20, 20, 20, 20, 20]\n" 393 | ] 394 | } 395 | ], 396 | "source": [ 397 | "li.pop(0) #index\n", 398 | "print(li)" 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": 53, 404 | "metadata": {}, 405 | "outputs": [ 406 | { 407 | "data": { 408 | "text/plain": [ 409 | "[20, 20, 20, 20, 90, 56, 1, 12, 77, 2, 1]" 410 | ] 411 | }, 412 | "execution_count": 53, 413 | "metadata": {}, 414 | "output_type": "execute_result" 415 | } 416 | ], 417 | "source": [ 418 | "li.reverse()\n", 419 | "li" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 55, 425 | "metadata": {}, 426 | "outputs": [ 427 | { 428 | "name": "stdout", 429 | "output_type": "stream", 430 | "text": [ 431 | "increasing order [1, 1, 2, 12, 20, 20, 20, 20, 56, 77, 90]\n", 432 | "decreasing order [90, 77, 56, 20, 20, 20, 20, 12, 2, 1, 1]\n" 433 | ] 434 | } 435 | ], 436 | "source": [ 437 | "li.sort()\n", 438 | "print(\"increasing order\",li)\n", 439 | "li.sort(reverse=True)\n", 440 | "print(\"decreasing order\",li)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 56, 446 | "metadata": {}, 447 | "outputs": [ 448 | { 449 | "name": "stdout", 450 | "output_type": "stream", 451 | "text": [ 452 | "[23, 45, 67, 89, 10, 24, 56, 78, 90]\n", 453 | "[10, 24, 56, 78, 90]\n" 454 | ] 455 | } 456 | ], 457 | "source": [ 458 | "l1=[23,45,67,89]\n", 459 | "l2=[10,24,56,78,90]\n", 460 | "l1.extend(l2)\n", 461 | "print(l1)\n", 462 | "print(l2)" 463 | ] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": 74, 468 | "metadata": {}, 469 | "outputs": [ 470 | { 471 | "name": "stdout", 472 | "output_type": "stream", 473 | "text": [ 474 | "[7, 34, 2, 56]\n", 475 | "[7, 34, 2, 56]\n", 476 | "[7, 34, 2, 56, 90]\n", 477 | "[7, 34, 2, 56, 90]\n" 478 | ] 479 | } 480 | ], 481 | "source": [ 482 | "#assignment\n", 483 | "t=[7,34,2,56]\n", 484 | "t1=t\n", 485 | "print(t1)\n", 486 | "print(t)\n", 487 | "t1.append(90)\n", 488 | "print(t1)\n", 489 | "print(t)" 490 | ] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": null, 495 | "metadata": {}, 496 | "outputs": [], 497 | "source": [] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": 75, 502 | "metadata": {}, 503 | "outputs": [ 504 | { 505 | "name": "stdout", 506 | "output_type": "stream", 507 | "text": [ 508 | "[7, 34, 2, 56]\n", 509 | "[7, 34, 2, 56]\n", 510 | "[7, 34, 2, 56, 90]\n", 511 | "[7, 34, 2, 56]\n" 512 | ] 513 | } 514 | ], 515 | "source": [ 516 | "#copy\n", 517 | "t=[7,34,2,56]\n", 518 | "t2=t.copy()\n", 519 | "print(t2)\n", 520 | "print(t)\n", 521 | "t2.append(90)\n", 522 | "print(t2)\n", 523 | "print(t)" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 76, 529 | "metadata": {}, 530 | "outputs": [ 531 | { 532 | "data": { 533 | "text/plain": [ 534 | "[7, 34, 2, 56, 90]" 535 | ] 536 | }, 537 | "execution_count": 76, 538 | "metadata": {}, 539 | "output_type": "execute_result" 540 | } 541 | ], 542 | "source": [ 543 | "t2" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": 77, 549 | "metadata": {}, 550 | "outputs": [], 551 | "source": [ 552 | "t2.clear()" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": 78, 558 | "metadata": {}, 559 | "outputs": [ 560 | { 561 | "data": { 562 | "text/plain": [ 563 | "[]" 564 | ] 565 | }, 566 | "execution_count": 78, 567 | "metadata": {}, 568 | "output_type": "execute_result" 569 | } 570 | ], 571 | "source": [ 572 | "t2" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 79, 578 | "metadata": {}, 579 | "outputs": [], 580 | "source": [ 581 | "del t2" 582 | ] 583 | }, 584 | { 585 | "cell_type": "code", 586 | "execution_count": 80, 587 | "metadata": {}, 588 | "outputs": [ 589 | { 590 | "ename": "NameError", 591 | "evalue": "name 't2' is not defined", 592 | "output_type": "error", 593 | "traceback": [ 594 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 595 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 596 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mt2\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 597 | "\u001b[1;31mNameError\u001b[0m: name 't2' is not defined" 598 | ] 599 | } 600 | ], 601 | "source": [ 602 | "t2" 603 | ] 604 | }, 605 | { 606 | "cell_type": "code", 607 | "execution_count": null, 608 | "metadata": {}, 609 | "outputs": [], 610 | "source": [] 611 | }, 612 | { 613 | "cell_type": "code", 614 | "execution_count": 83, 615 | "metadata": {}, 616 | "outputs": [ 617 | { 618 | "name": "stdout", 619 | "output_type": "stream", 620 | "text": [ 621 | "[2, 4, 6, 8, 10]\n" 622 | ] 623 | } 624 | ], 625 | "source": [ 626 | "# example\n", 627 | "t=[1,2,3,4,5]\n", 628 | "li=[]#2,4\n", 629 | "for i in t:#2\n", 630 | " li.append(i*2)\n", 631 | "print(li)" 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": 84, 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "name": "stdout", 641 | "output_type": "stream", 642 | "text": [ 643 | "[12, 13, 14, 15]\n" 644 | ] 645 | } 646 | ], 647 | "source": [ 648 | "#duplicates remove\n", 649 | "t=[12,12,13,13,12,14,15]\n", 650 | "li=[]#12,13,14,15\n", 651 | "for i in t:\n", 652 | " if i not in li:\n", 653 | " li.append(i)\n", 654 | "print(li)" 655 | ] 656 | }, 657 | { 658 | "cell_type": "code", 659 | "execution_count": 85, 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "name": "stdout", 664 | "output_type": "stream", 665 | "text": [ 666 | "[14, 15]\n" 667 | ] 668 | } 669 | ], 670 | "source": [ 671 | "#unique elements\n", 672 | "t=[12,12,13,13,12,14,15]\n", 673 | "li=[]#14,15\n", 674 | "for i in t:\n", 675 | " if t.count(i)==1:\n", 676 | " li.append(i)\n", 677 | "print(li)" 678 | ] 679 | }, 680 | { 681 | "cell_type": "code", 682 | "execution_count": 87, 683 | "metadata": {}, 684 | "outputs": [ 685 | { 686 | "name": "stdout", 687 | "output_type": "stream", 688 | "text": [ 689 | "3\n", 690 | "4\n" 691 | ] 692 | } 693 | ], 694 | "source": [ 695 | "l=[12,12,12,3,4,6,6]\n", 696 | "for i in l:\n", 697 | " if l.count(i)==1:\n", 698 | " print(i)" 699 | ] 700 | }, 701 | { 702 | "cell_type": "code", 703 | "execution_count": null, 704 | "metadata": {}, 705 | "outputs": [], 706 | "source": [ 707 | "l1=[9,8,7,6]\n", 708 | "l2=[[0],[0,2],[1,2],[4,1,2]]\n", 709 | "o/p:\n", 710 | " [[9],[8,10],[8,9],[10,7,8]]" 711 | ] 712 | }, 713 | { 714 | "cell_type": "code", 715 | "execution_count": 88, 716 | "metadata": {}, 717 | "outputs": [ 718 | { 719 | "name": "stdout", 720 | "output_type": "stream", 721 | "text": [ 722 | "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] " 723 | ] 724 | } 725 | ], 726 | "source": [ 727 | "print(dir(str),end=\" \")" 728 | ] 729 | }, 730 | { 731 | "cell_type": "code", 732 | "execution_count": 96, 733 | "metadata": {}, 734 | "outputs": [ 735 | { 736 | "data": { 737 | "text/plain": [ 738 | "['programming', 'python', 'python']" 739 | ] 740 | }, 741 | "execution_count": 96, 742 | "metadata": {}, 743 | "output_type": "execute_result" 744 | } 745 | ], 746 | "source": [ 747 | "l=['python','programming','python']\n", 748 | "l.count('python')\n", 749 | "l.sort()\n", 750 | "l" 751 | ] 752 | }, 753 | { 754 | "cell_type": "code", 755 | "execution_count": 2, 756 | "metadata": {}, 757 | "outputs": [], 758 | "source": [ 759 | "l=['p','y','t','h']\n", 760 | "l.sort()" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": 3, 766 | "metadata": {}, 767 | "outputs": [ 768 | { 769 | "data": { 770 | "text/plain": [ 771 | "['h', 'p', 't', 'y']" 772 | ] 773 | }, 774 | "execution_count": 3, 775 | "metadata": {}, 776 | "output_type": "execute_result" 777 | } 778 | ], 779 | "source": [ 780 | "l" 781 | ] 782 | }, 783 | { 784 | "cell_type": "code", 785 | "execution_count": 4, 786 | "metadata": {}, 787 | "outputs": [ 788 | { 789 | "name": "stdout", 790 | "output_type": "stream", 791 | "text": [ 792 | "['y', 't', 'p', 'h']\n" 793 | ] 794 | } 795 | ], 796 | "source": [ 797 | "l.reverse()\n", 798 | "print(l)" 799 | ] 800 | }, 801 | { 802 | "cell_type": "code", 803 | "execution_count": null, 804 | "metadata": {}, 805 | "outputs": [], 806 | "source": [] 807 | }, 808 | { 809 | "cell_type": "code", 810 | "execution_count": null, 811 | "metadata": {}, 812 | "outputs": [], 813 | "source": [] 814 | }, 815 | { 816 | "cell_type": "code", 817 | "execution_count": null, 818 | "metadata": {}, 819 | "outputs": [], 820 | "source": [] 821 | } 822 | ], 823 | "metadata": { 824 | "kernelspec": { 825 | "display_name": "Python 3", 826 | "language": "python", 827 | "name": "python3" 828 | }, 829 | "language_info": { 830 | "codemirror_mode": { 831 | "name": "ipython", 832 | "version": 3 833 | }, 834 | "file_extension": ".py", 835 | "mimetype": "text/x-python", 836 | "name": "python", 837 | "nbconvert_exporter": "python", 838 | "pygments_lexer": "ipython3", 839 | "version": "3.7.3" 840 | } 841 | }, 842 | "nbformat": 4, 843 | "nbformat_minor": 2 844 | } 845 | -------------------------------------------------------------------------------- /2nd July 2020.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "### File handling and file data processing\n", 8 | "- used to store related information\n", 9 | "- steps\n", 10 | " - open file\n", 11 | " - use open(), it returns a file object\n", 12 | " - open(filename,mode)\n", 13 | " - perform operations\n", 14 | " - read -- read data\n", 15 | " - write -- add data\n", 16 | " - append -- add data to existing data\n", 17 | " - close file\n", 18 | " - use close()\n", 19 | "- Modes\n", 20 | " - read mode --- r\n", 21 | " - write mode --- w\n", 22 | " - append mode --- a" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "Hello Guys welcome to online python programming session\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "f = open('Datafiles/demo.txt')\n", 40 | "data = f.read()\n", 41 | "print(data)\n", 42 | "f.close()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 2, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "Hello Guys welcome to online python programming session\n" 55 | ] 56 | } 57 | ], 58 | "source": [ 59 | "# The word \"with\" automatically closes the file at the end of operation\n", 60 | "with open('Datafiles/demo.txt') as info:\n", 61 | " information = info.read()\n", 62 | " print(information)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 4, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "name": "stdout", 72 | "output_type": "stream", 73 | "text": [ 74 | "6\n", 75 | "APSSDC\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "with open('Datafiles/demo.txt','w') as info:\n", 81 | " information = info.write(\"APSSDC\")\n", 82 | " print(information)\n", 83 | "with open('Datafiles/demo.txt') as info:\n", 84 | " information = info.read()\n", 85 | " print(information)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 5, 91 | "metadata": {}, 92 | "outputs": [ 93 | { 94 | "name": "stdout", 95 | "output_type": "stream", 96 | "text": [ 97 | "15\n", 98 | "APSSDC python program\n" 99 | ] 100 | } 101 | ], 102 | "source": [ 103 | "with open('Datafiles/demo.txt','a') as f:\n", 104 | " fh = f.write(\" python program\")\n", 105 | " print(fh)\n", 106 | "with open('Datafiles/demo.txt') as info:\n", 107 | " information = info.read()\n", 108 | " print(information)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "- append --- data is added at the end\n", 116 | "- To overcome this\n", 117 | " - tell()\n", 118 | " - helps to know cursor position\n", 119 | " - seek()\n", 120 | " - helps to move cursor to particular position" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 8, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "21\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "with open('Datafiles/demo.txt') as f:\n", 138 | " fh = f.read()\n", 139 | " print(f.tell())\n", 140 | "#type(fh)" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 10, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "name": "stdout", 150 | "output_type": "stream", 151 | "text": [ 152 | " python pr\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "with open('Datafiles/demo.txt') as f:\n", 158 | " f.read()\n", 159 | " f.seek(6)\n", 160 | " print(f.read(10))" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 13, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "with open('Datafiles/demo.txt','w') as f:\n", 170 | " f.seek(6)\n", 171 | " f.write(\"Todays session on files concept\")" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 15, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "with open('Datafiles/demo1.txt','w') as f:\n", 181 | " fh = f.write(\"Hiiiii\")" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 17, 187 | "metadata": {}, 188 | "outputs": [ 189 | { 190 | "name": "stdout", 191 | "output_type": "stream", 192 | "text": [ 193 | "['Hii', 'welcome', 'to', 'python', 'online']\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "with open('Datafiles/demo.txt') as f:\n", 199 | " fh = f.read()\n", 200 | " words = fh.split()\n", 201 | " print(words)" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 19, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "Hii welcome to python online\n", 214 | "\n", 215 | "Session\n", 216 | "\n" 217 | ] 218 | } 219 | ], 220 | "source": [ 221 | "with open('Datafiles/demo.txt') as f:\n", 222 | " print(f.readline())\n", 223 | " print(f.readline())" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 20, 229 | "metadata": {}, 230 | "outputs": [ 231 | { 232 | "name": "stdout", 233 | "output_type": "stream", 234 | "text": [ 235 | "['Hii welcome to python online\\n', 'Session\\n', 'conducted\\n', 'by\\n', 'APSSDC\\n', 'Todays\\n', 'Concept is\\n', 'Files']\n" 236 | ] 237 | } 238 | ], 239 | "source": [ 240 | "with open('Datafiles/demo.txt') as f:\n", 241 | " print(f.readlines())" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 21, 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "Hii welcome to python online\n", 254 | "Session\n", 255 | "conducted\n", 256 | "by\n", 257 | "APSSDC\n", 258 | "Todays\n", 259 | "Concept is\n", 260 | "Files" 261 | ] 262 | } 263 | ], 264 | "source": [ 265 | "with open('Datafiles/demo.txt') as f:\n", 266 | " fh = f.readlines()\n", 267 | " for i in fh:\n", 268 | " print(i,end = \"\")" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 23, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "name": "stdout", 278 | "output_type": "stream", 279 | "text": [ 280 | "8\n" 281 | ] 282 | }, 283 | { 284 | "data": { 285 | "text/plain": [ 286 | "list" 287 | ] 288 | }, 289 | "execution_count": 23, 290 | "metadata": {}, 291 | "output_type": "execute_result" 292 | } 293 | ], 294 | "source": [ 295 | "with open('Datafiles/demo.txt') as f:\n", 296 | " fh = f.readlines()\n", 297 | " print(len(fh))\n", 298 | "type(fh)" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 24, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "name": "stdout", 308 | "output_type": "stream", 309 | "text": [ 310 | "68\n" 311 | ] 312 | } 313 | ], 314 | "source": [ 315 | "def charcount(filepath):\n", 316 | " with open(filepath) as f:\n", 317 | " c = 0\n", 318 | " fh = f.read()\n", 319 | " for i in fh:\n", 320 | " if i != \"\\n\" and i != \" \":\n", 321 | " c += 1\n", 322 | " print(c)\n", 323 | "filepath = 'Datafiles/demo.txt'\n", 324 | "charcount(filepath)" 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "metadata": {}, 330 | "source": [ 331 | "- Tasks\n", 332 | " - words count\n", 333 | " - unique words count\n", 334 | " - freuency of words\n", 335 | " - is : 2\n", 336 | " - python : 1" 337 | ] 338 | }, 339 | { 340 | "cell_type": "markdown", 341 | "metadata": {}, 342 | "source": [ 343 | "- File data processing\n", 344 | " - working with data in the file and doing modifications to that file" 345 | ] 346 | }, 347 | { 348 | "cell_type": "code", 349 | "execution_count": 9, 350 | "metadata": {}, 351 | "outputs": [], 352 | "source": [ 353 | "# Generate students marks randomly\n", 354 | "from random import randint\n", 355 | "def marksgen(n,lb,ub):\n", 356 | " with open('Datafiles/marks.txt','w') as f:\n", 357 | " for i in range(0,n):\n", 358 | " r = randint(lb,ub)\n", 359 | " f.write(str(r)+'\\n')\n", 360 | " return\n", 361 | "marksgen(50,1,100)" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": 10, 367 | "metadata": {}, 368 | "outputs": [ 369 | { 370 | "data": { 371 | "text/plain": [ 372 | "39.44" 373 | ] 374 | }, 375 | "execution_count": 10, 376 | "metadata": {}, 377 | "output_type": "execute_result" 378 | } 379 | ], 380 | "source": [ 381 | "def classavg(filepath):\n", 382 | " with open(filepath) as f:\n", 383 | " filedata = f.read()\n", 384 | " marks = filedata.split()\n", 385 | " sum = 0\n", 386 | " for mark in marks:\n", 387 | " sum += int(mark)\n", 388 | " return sum / len(marks)\n", 389 | "filepath = 'Datafiles/marks.txt'\n", 390 | "classavg(filepath)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "markdown", 395 | "metadata": {}, 396 | "source": [ 397 | "- Tasks\n", 398 | " - % of students passed\n", 399 | " - marks above or equal to 35\n", 400 | " - % of students failed\n", 401 | " - marks below 35\n", 402 | " - % of students with distinction\n", 403 | " - marks above or equal to 80\n", 404 | " - Highest mark frequency\n", 405 | " - Number of students with highest marks\n", 406 | " - Lowest mark frequency\n", 407 | " - Number of students with lowest marks" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 31, 413 | "metadata": {}, 414 | "outputs": [], 415 | "source": [ 416 | "# Find and replace a word in different file\n", 417 | "f = open('Datafiles/data.txt')\n", 418 | "f2 = open('Datafiles/data2.txt','w')\n", 419 | "for line in f:\n", 420 | " f2.write(line.replace('word','PYTHON'))\n", 421 | "f.close()\n", 422 | "f2.close()" 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": 28, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [ 431 | "# replace word in the same file\n", 432 | "f = open('Datafiles/info.txt')\n", 433 | "data = f.read()\n", 434 | "data = data.replace('word','FILES')\n", 435 | "f.close()\n", 436 | "f = open('Datafiles/info.txt','w')\n", 437 | "f.write(data)\n", 438 | "f.close()" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 1, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "data": { 448 | "text/plain": [ 449 | "19" 450 | ] 451 | }, 452 | "execution_count": 1, 453 | "metadata": {}, 454 | "output_type": "execute_result" 455 | } 456 | ], 457 | "source": [ 458 | "# Words Count\n", 459 | "def wordscount(filepath):\n", 460 | " with open(filepath) as f:\n", 461 | " fh = f.read()\n", 462 | " data = fh.split()\n", 463 | " wc = len(data)\n", 464 | " return wc\n", 465 | "filepath = 'Datafiles/task.txt'\n", 466 | "wordscount(filepath)" 467 | ] 468 | }, 469 | { 470 | "cell_type": "code", 471 | "execution_count": 5, 472 | "metadata": {}, 473 | "outputs": [ 474 | { 475 | "name": "stdout", 476 | "output_type": "stream", 477 | "text": [ 478 | "['Good', 'Afternoon', 'everyone', 'welcome', 'to', 'python', 'online', 'session', 'on', 'file', 'handling', 'and', 'data', 'processing', '2nd', 'July', '2020'] " 479 | ] 480 | } 481 | ], 482 | "source": [ 483 | "# Unique words count\n", 484 | "def uniquewords(filepath):\n", 485 | " uw = []\n", 486 | " with open(filepath) as f:\n", 487 | " fh = f.read()\n", 488 | " data = fh.split()\n", 489 | " for word in data:\n", 490 | " if word not in uw:\n", 491 | " uw.append(word)\n", 492 | " print(uw,end=\" \")\n", 493 | "filepath = 'Datafiles/task.txt'\n", 494 | "uniquewords(filepath)\n", 495 | " " 496 | ] 497 | }, 498 | { 499 | "cell_type": "code", 500 | "execution_count": 6, 501 | "metadata": {}, 502 | "outputs": [ 503 | { 504 | "name": "stdout", 505 | "output_type": "stream", 506 | "text": [ 507 | "{'Good': 1, 'Afternoon': 1, 'everyone': 1, 'welcome': 1, 'to': 1, 'python': 1, 'online': 1, 'session': 1, 'on': 2, 'file': 2, 'handling': 1, 'and': 1, 'data': 1, 'processing': 1, '2nd': 1, 'July': 1, '2020': 1} " 508 | ] 509 | } 510 | ], 511 | "source": [ 512 | "# Words Frequency\n", 513 | "def wordsfreq(filepath):\n", 514 | " with open(filepath) as f:\n", 515 | " d = {}\n", 516 | " fh = f.read()\n", 517 | " data = fh.split()\n", 518 | " for word in data:\n", 519 | " a = data.count(word)\n", 520 | " d[word] = a\n", 521 | " print(d,end=\" \")\n", 522 | "filepath = 'Datafiles/task.txt'\n", 523 | "wordsfreq(filepath)" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 17, 529 | "metadata": {}, 530 | "outputs": [ 531 | { 532 | "name": "stdout", 533 | "output_type": "stream", 534 | "text": [ 535 | "% of students passed 50.0\n", 536 | "% of students failed 50.0\n", 537 | "% of students with distinction 10.0\n", 538 | "Highest mark frequency 2\n", 539 | "Lowest mark frequency 1\n" 540 | ] 541 | } 542 | ], 543 | "source": [ 544 | "# Student report Generation\n", 545 | "def reportgen(filepath):\n", 546 | " with open(filepath) as f:\n", 547 | " filedata = f.read()\n", 548 | " lines = filedata.split()\n", 549 | " passcount = 0\n", 550 | " distcount = 0\n", 551 | " highcount = 0\n", 552 | " lowcount = 0\n", 553 | " highestmarks = max(lines)\n", 554 | " lowestmarks = min(lines)\n", 555 | " for mark in lines:\n", 556 | " if int(mark) >= 35:\n", 557 | " passcount += 1\n", 558 | " if int(mark) >= 80:\n", 559 | " distcount += 1\n", 560 | " if int(mark) == int(highestmarks):\n", 561 | " highcount += 1\n", 562 | " if int(mark) == int(lowestmarks):\n", 563 | " lowcount += 1\n", 564 | " passpercentage = (passcount/len(lines))*100\n", 565 | " failedpercentage = 100 - passpercentage\n", 566 | " distinctionpercentage = (distcount/len(lines))*100\n", 567 | " print(\"% of students passed \",passpercentage)\n", 568 | " print(\"% of students failed \",failedpercentage)\n", 569 | " print(\"% of students with distinction \",distinctionpercentage)\n", 570 | " print(\"Highest mark frequency \",highcount)\n", 571 | " print(\"Lowest mark frequency\",lowcount)\n", 572 | "filepath = 'Datafiles/marks.txt'\n", 573 | "reportgen(filepath)" 574 | ] 575 | }, 576 | { 577 | "cell_type": "code", 578 | "execution_count": 16, 579 | "metadata": {}, 580 | "outputs": [ 581 | { 582 | "name": "stdout", 583 | "output_type": "stream", 584 | "text": [ 585 | "95 65 67 60 50 73 51 8 9 8 27 20 15 9 47 100 95 69 3 70 56 13 35 17 29 41 15 26 15 74 71 2 5 59 29 1 40 47 47 81 12 79 6 11 47 24 30 24 89 6 " 586 | ] 587 | } 588 | ], 589 | "source": [ 590 | "def marksfreq(filepath):\n", 591 | " with open(filepath) as f:\n", 592 | " fh = f.read()\n", 593 | " marks = fh.split()\n", 594 | " for mark in marks:\n", 595 | " print(mark,end=\" \")\n", 596 | " #print(max(marks))\n", 597 | " #print(min(marks))\n", 598 | "filepath = 'Datafiles/marks.txt'\n", 599 | "marksfreq(filepath)" 600 | ] 601 | }, 602 | { 603 | "cell_type": "code", 604 | "execution_count": null, 605 | "metadata": {}, 606 | "outputs": [], 607 | "source": [] 608 | } 609 | ], 610 | "metadata": { 611 | "kernelspec": { 612 | "display_name": "Python 3", 613 | "language": "python", 614 | "name": "python3" 615 | }, 616 | "language_info": { 617 | "codemirror_mode": { 618 | "name": "ipython", 619 | "version": 3 620 | }, 621 | "file_extension": ".py", 622 | "mimetype": "text/x-python", 623 | "name": "python", 624 | "nbconvert_exporter": "python", 625 | "pygments_lexer": "ipython3", 626 | "version": "3.7.1" 627 | } 628 | }, 629 | "nbformat": 4, 630 | "nbformat_minor": 2 631 | } 632 | -------------------------------------------------------------------------------- /6th July 2020.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Object oriented Programming\n", 8 | "- Class\n", 9 | " - collection of data and methods\n", 10 | "- objects\n", 11 | " - instance of a class\n", 12 | "- inheritance" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": null, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "# class syntax\n", 22 | "class classname:\n", 23 | " def functionName:\n", 24 | " statements\n", 25 | " statements\n", 26 | "obj = classname()" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "data": { 36 | "text/plain": [ 37 | "<__main__.Sample at 0x1ee3b42a208>" 38 | ] 39 | }, 40 | "execution_count": 1, 41 | "metadata": {}, 42 | "output_type": "execute_result" 43 | } 44 | ], 45 | "source": [ 46 | "class Sample: # class\n", 47 | " pass\n", 48 | "\n", 49 | "ob = Sample() # object\n", 50 | "ob" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 3, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "data": { 60 | "text/plain": [ 61 | "<__main__.Example at 0x1ee3b42a668>" 62 | ] 63 | }, 64 | "execution_count": 3, 65 | "metadata": {}, 66 | "output_type": "execute_result" 67 | } 68 | ], 69 | "source": [ 70 | "class Example:\n", 71 | " '''this is a docstring example'''\n", 72 | "\n", 73 | "a = Example()\n", 74 | "a" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "'this is a docstring example'" 86 | ] 87 | }, 88 | "execution_count": 4, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "a.__doc__" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 5, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "Constructor has executed\n", 107 | "Constructor has executed\n", 108 | "<__main__.Student object at 0x000001EE3B42AEF0>\n", 109 | "<__main__.Student object at 0x000001EE3B42AF98>\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "class Student:\n", 115 | " def __init__(self,rollno,name):\n", 116 | " self.rollno =rollno\n", 117 | " self.name = name\n", 118 | " print(\"Constructor has executed\")\n", 119 | "\n", 120 | "a = Student(123,'poojitha')\n", 121 | "b = Student(456,\"sudha\")\n", 122 | "print(a)\n", 123 | "print(b) " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 14, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "name": "stdout", 133 | "output_type": "stream", 134 | "text": [ 135 | "in init method of employee class\n", 136 | "employee id is: 1234876\n", 137 | "employee name is: python\n" 138 | ] 139 | } 140 | ], 141 | "source": [ 142 | "class Employee:\n", 143 | " def __init__(self,empid,empname):\n", 144 | " self.empid = empid\n", 145 | " self.empname = empname\n", 146 | " print(\"in init method of employee class\")\n", 147 | " def show(self):\n", 148 | " print(\"employee id is: \",self.empid)\n", 149 | " print(\"employee name is: \",self.empname)\n", 150 | " \n", 151 | "abc = Employee(1234876,\"python\")\n", 152 | "abc.show()" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 15, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdout", 162 | "output_type": "stream", 163 | "text": [ 164 | "addition: 30\n" 165 | ] 166 | } 167 | ], 168 | "source": [ 169 | "class Calci:\n", 170 | " def __init__(self,num1,num2):\n", 171 | " self.num1 = num1\n", 172 | " self.num2 = num2\n", 173 | " def add(self):\n", 174 | " print(\"addition:\",self.num1 + self.num2)\n", 175 | "\n", 176 | "ab = Calci(10,20)\n", 177 | "ab.add()" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "### Types of methods\n", 185 | "- instance method\n", 186 | "- class method\n", 187 | "- static method" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 19, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "name: name\n", 200 | "empid: 12345\n", 201 | "Salary 13456\n", 202 | "Company name is APSSDC\n", 203 | "12\n" 204 | ] 205 | } 206 | ], 207 | "source": [ 208 | "class EmployeeDetails:\n", 209 | " cname = \"APSSDC\"\n", 210 | " def __init__(self,empid,name,salary):\n", 211 | " self.empid = empid\n", 212 | " self.name = name\n", 213 | " self.salary = salary\n", 214 | " \n", 215 | " def display(self): # instance method\n", 216 | " print(\"name:\",self.name)\n", 217 | " print(\"empid:\",self.empid)\n", 218 | " print(\"Salary\",self.salary)\n", 219 | " \n", 220 | " def Company(cls): # class method\n", 221 | " print(\"Company name is \",cls.cname)\n", 222 | " \n", 223 | " def mul(d,f): # static method\n", 224 | " print(d*f)\n", 225 | " \n", 226 | " \n", 227 | "a = EmployeeDetails(12345,\"name\",13456)\n", 228 | "a.display() \n", 229 | "a.Company() \n", 230 | "EmployeeDetails.mul(3,4)" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "metadata": {}, 236 | "source": [ 237 | "### Inheritance:\n", 238 | " - Acquiring properties from parent class to child class\n", 239 | "#### Types of inheritance\n", 240 | "- Single\n", 241 | "- Multiple\n", 242 | "- multilevel\n", 243 | "- Hierachical" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 21, 249 | "metadata": {}, 250 | "outputs": [ 251 | { 252 | "name": "stdout", 253 | "output_type": "stream", 254 | "text": [ 255 | "three method\n", 256 | "one method\n", 257 | "two method\n" 258 | ] 259 | } 260 | ], 261 | "source": [ 262 | "# Single Inheritance: first ---> second\n", 263 | "\n", 264 | "class first: # parent class\n", 265 | " def one(self):\n", 266 | " print(\"one method\")\n", 267 | " def two(self):\n", 268 | " print(\"two method\")\n", 269 | " \n", 270 | "class second(first): # child class\n", 271 | " def three(self):\n", 272 | " print(\"three method\")\n", 273 | " def four(self):\n", 274 | " print(\"four method\")\n", 275 | " \n", 276 | "a = second()\n", 277 | "a.three()\n", 278 | "a.one()\n", 279 | "a.two()" 280 | ] 281 | }, 282 | { 283 | "cell_type": "markdown", 284 | "metadata": {}, 285 | "source": [ 286 | "### Multiple Inheritance\n", 287 | "- If a class is derived from more than one parent class then we say it as multiple inheritance" 288 | ] 289 | }, 290 | { 291 | "cell_type": "code", 292 | "execution_count": 3, 293 | "metadata": {}, 294 | "outputs": [ 295 | { 296 | "name": "stdout", 297 | "output_type": "stream", 298 | "text": [ 299 | "Mothername is: sita\n", 300 | "fathername is: ram\n", 301 | "Parent class: sita\n", 302 | "Parent class: ram\n" 303 | ] 304 | } 305 | ], 306 | "source": [ 307 | "class Parent:\n", 308 | " mothername=\"\"\n", 309 | "\n", 310 | " def mother(self):\n", 311 | " print(\"Parent class:\",self.mothername)\n", 312 | "\n", 313 | "class ParentOne:\n", 314 | " fathername=\"\"\n", 315 | "\n", 316 | " def Father(self):\n", 317 | " print(\"Parent class:\",self.fathername)\n", 318 | " \n", 319 | "class child(Parent,ParentOne):\n", 320 | " def parents(self):\n", 321 | " print(\"Mothername is:\",self.mothername)\n", 322 | " print(\"fathername is:\",self.fathername)\n", 323 | " \n", 324 | " \n", 325 | "s = child()\n", 326 | "s.mothername = \"sita\"\n", 327 | "s.fathername = \"ram\"\n", 328 | "s.parents()\n", 329 | "s.mother()\n", 330 | "s.Father()" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": null, 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [ 339 | "# Task\n", 340 | "\n", 341 | "## Inpatient : \n", 342 | "# name\n", 343 | "# mbl number\n", 344 | "# address\n", 345 | "# disease name\n", 346 | "# staycount\n", 347 | "# type of ward\n", 348 | "# age\n", 349 | "\n", 350 | "## Outpatient:\n", 351 | "# name\n", 352 | "# mbl number\n", 353 | "# address\n", 354 | "# age" 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "execution_count": 6, 360 | "metadata": {}, 361 | "outputs": [ 362 | { 363 | "name": "stdout", 364 | "output_type": "stream", 365 | "text": [ 366 | "grand father\n", 367 | "father\n", 368 | "father\n", 369 | "grand father\n" 370 | ] 371 | } 372 | ], 373 | "source": [ 374 | "# Multilevel Inheritance\n", 375 | "# base --> Intermediate class --> child \n", 376 | "\n", 377 | "class GrandFather:\n", 378 | " grandfathername =\"\"\n", 379 | " def grandfather(self):\n", 380 | " print(self.grandfathername)\n", 381 | " \n", 382 | "class Father(GrandFather):\n", 383 | " fathername =\"\"\n", 384 | " def father(self):\n", 385 | " print(self.fathername)\n", 386 | " \n", 387 | "class child(Father):\n", 388 | " def son(self):\n", 389 | " print(self.grandfathername)\n", 390 | " print(self.fathername)\n", 391 | "\n", 392 | " \n", 393 | "s1 = child()\n", 394 | "s1.fathername = \"father\"\n", 395 | "s1.grandfathername = \"grand father\"\n", 396 | "s1.son()\n", 397 | "s1.father()\n", 398 | "s1.grandfather()" 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": null, 404 | "metadata": {}, 405 | "outputs": [], 406 | "source": [ 407 | "# vehicles task\n", 408 | "\n", 409 | "## two wheelers\n", 410 | "# name\n", 411 | "# fueltype or not\n", 412 | "# travelers count\n", 413 | "\n", 414 | "# three wheelers\n", 415 | "# name\n", 416 | "# travelers count\n", 417 | "\n", 418 | "# four wheelers\n", 419 | "# name\n", 420 | "# travlers count" 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": 7, 426 | "metadata": {}, 427 | "outputs": [], 428 | "source": [ 429 | "# hierarichal inheritance\n", 430 | "# one or more classes are derived from a single parent class" 431 | ] 432 | }, 433 | { 434 | "cell_type": "code", 435 | "execution_count": 12, 436 | "metadata": {}, 437 | "outputs": [ 438 | { 439 | "name": "stdout", 440 | "output_type": "stream", 441 | "text": [ 442 | "this is parent class\n", 443 | "this is parent class\n", 444 | "this is chilld1 class\n", 445 | "this is child2 class\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "class parent:\n", 451 | " def parent(self):\n", 452 | " print(\"this is parent class\")\n", 453 | " \n", 454 | "class child1(parent):\n", 455 | " def child1(self):\n", 456 | " print(\"this is chilld1 class\")\n", 457 | " \n", 458 | "class child2(parent):\n", 459 | " def child2(self):\n", 460 | " print(\"this is child2 class\")\n", 461 | " \n", 462 | "ob1 = child1()\n", 463 | "ob2 = child2()\n", 464 | "\n", 465 | "ob1.parent()\n", 466 | "ob2.parent()\n", 467 | "\n", 468 | "ob1.child1()\n", 469 | "ob2.child2()" 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "execution_count": null, 475 | "metadata": {}, 476 | "outputs": [], 477 | "source": [] 478 | } 479 | ], 480 | "metadata": { 481 | "kernelspec": { 482 | "display_name": "Python 3", 483 | "language": "python", 484 | "name": "python3" 485 | }, 486 | "language_info": { 487 | "codemirror_mode": { 488 | "name": "ipython", 489 | "version": 3 490 | }, 491 | "file_extension": ".py", 492 | "mimetype": "text/x-python", 493 | "name": "python", 494 | "nbconvert_exporter": "python", 495 | "pygments_lexer": "ipython3", 496 | "version": "3.7.1" 497 | } 498 | }, 499 | "nbformat": 4, 500 | "nbformat_minor": 2 501 | } 502 | -------------------------------------------------------------------------------- /Datafiles/data.txt: -------------------------------------------------------------------------------- 1 | Try to replace a word with new word -------------------------------------------------------------------------------- /Datafiles/data1.txt: -------------------------------------------------------------------------------- 1 | Try to replace a PYTHON with new PYTHON -------------------------------------------------------------------------------- /Datafiles/demo.txt: -------------------------------------------------------------------------------- 1 | Hii welcome to python online 2 | Session 3 | conducted 4 | by 5 | APSSDC 6 | Todays 7 | Concept is 8 | Files -------------------------------------------------------------------------------- /Datafiles/demo1.txt: -------------------------------------------------------------------------------- 1 | Hiiiii -------------------------------------------------------------------------------- /Datafiles/info.txt: -------------------------------------------------------------------------------- 1 | Replace a FILES with a new FILES -------------------------------------------------------------------------------- /Datafiles/marks.txt: -------------------------------------------------------------------------------- 1 | 95 2 | 65 3 | 67 4 | 60 5 | 50 6 | 73 7 | 51 8 | 8 9 | 9 10 | 8 11 | 27 12 | 20 13 | 15 14 | 9 15 | 47 16 | 100 17 | 95 18 | 69 19 | 3 20 | 70 21 | 56 22 | 13 23 | 35 24 | 17 25 | 29 26 | 41 27 | 15 28 | 26 29 | 15 30 | 74 31 | 71 32 | 2 33 | 5 34 | 59 35 | 29 36 | 1 37 | 40 38 | 47 39 | 47 40 | 81 41 | 12 42 | 79 43 | 6 44 | 11 45 | 47 46 | 24 47 | 30 48 | 24 49 | 89 50 | 6 51 | -------------------------------------------------------------------------------- /Datafiles/task.txt: -------------------------------------------------------------------------------- 1 | Good Afternoon everyone welcome to python online session on file handling and file data processing on 2nd July 2020 -------------------------------------------------------------------------------- /June 4,2020(afternun).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Functional Programming" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Map ,filter and lambda" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# Map:\n", 24 | "- builtin function,it returns map object\n", 25 | "- to see the result we have to use list,tuple,set.\n", 26 | "-syntax:\n", 27 | " - map(function,iterable1,iterable2,.....)\n", 28 | "- it apply given function to each item of given iterable." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 12, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "name": "stdout", 38 | "output_type": "stream", 39 | "text": [ 40 | "23\n" 41 | ] 42 | } 43 | ], 44 | "source": [ 45 | "n=int(input())" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 13, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "['a', 'p', 'ss', 'dc']\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "s=\"a p ss dc\"\n", 63 | "print(s.split())" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "20 90 80 67\n", 73 | "20,90,80,67" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 16, 79 | "metadata": { 80 | "scrolled": true 81 | }, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "24 56 78 12 67\n", 88 | "\n", 89 | "[24, 56, 78, 12, 67]\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "#multiple inputs\n", 95 | "n=list(map(int,input().split()))\n", 96 | "print(type(n))\n", 97 | "print(n)" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 17, 103 | "metadata": {}, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "pavani ambika poojitha python\n", 110 | "\n", 111 | "['pavani', 'ambika', 'poojitha', 'python']\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "n=list(map(str,input().split()))\n", 117 | "print(type(n))\n", 118 | "print(n)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 18, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "p y t h o n\n", 131 | "\n", 132 | "('p', 'y', 't', 'h', 'o', 'n')\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "n=tuple(map(str,input().split()))\n", 138 | "print(type(n))\n", 139 | "print(n)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 20, 145 | "metadata": {}, 146 | "outputs": [ 147 | { 148 | "name": "stdout", 149 | "output_type": "stream", 150 | "text": [ 151 | "23 4 5 12 12 12 45 \n", 152 | "\n", 153 | "{'12', '45', '23', '4', '5'}\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "n=set(map(int,input().split()))\n", 159 | "print(type(n))\n", 160 | "print(n)" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": null, 166 | "metadata": {}, 167 | "outputs": [], 168 | "source": [ 169 | "map(function,iterable)" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 84, 175 | "metadata": {}, 176 | "outputs": [ 177 | { 178 | "name": "stdout", 179 | "output_type": "stream", 180 | "text": [ 181 | "[2, 4, 6, 8, 10]\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "def addition(n):\n", 187 | " return n+n\n", 188 | "r=list(map(addition,range(1,6)))\n", 189 | "print(r)" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 26, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "{1, 4, 9, 16, 25}\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "def squareof(n):\n", 207 | " return n*n\n", 208 | "r=set(map(squareof,range(1,6)))\n", 209 | "print(r)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 27, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "name": "stdout", 219 | "output_type": "stream", 220 | "text": [ 221 | "enter starting:1\n", 222 | "enter ending:10\n", 223 | "{64, 1, 4, 36, 100, 9, 16, 49, 81, 25}\n" 224 | ] 225 | } 226 | ], 227 | "source": [ 228 | "def squareof(n):\n", 229 | " return n*n\n", 230 | "start=int(input(\"enter starting:\"))\n", 231 | "end=int(input(\"enter ending:\"))\n", 232 | "r=set(map(squareof,range(start,end+1)))\n", 233 | "print(r)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 28, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "enter starting:1\n", 246 | "enter ending:10\n", 247 | "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "def squareof(n):\n", 253 | " return n*n\n", 254 | "start=int(input(\"enter starting:\"))\n", 255 | "end=int(input(\"enter ending:\"))\n", 256 | "r=list(map(squareof,range(start,end+1)))\n", 257 | "print(r)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 30, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "23 12 34 56 78\n", 270 | "203\n", 271 | "12\n", 272 | "78\n" 273 | ] 274 | } 275 | ], 276 | "source": [ 277 | "n=list(map(int,input().split()))\n", 278 | "print(sum(n))\n", 279 | "print(min(n))\n", 280 | "print(max(n))" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 59, 286 | "metadata": {}, 287 | "outputs": [], 288 | "source": [ 289 | "def uppercase(s):\n", 290 | " return str(s).upper()" 291 | ] 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": 44, 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [ 299 | "def print_upp(t):\n", 300 | " for x in t:\n", 301 | " print(x,end=\" \")" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 45, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "\n", 314 | "A B C " 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "#string\n", 320 | "result=map(uppercase,'abc')\n", 321 | "print(type(result))\n", 322 | "print_upp(result)" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 46, 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "name": "stdout", 332 | "output_type": "stream", 333 | "text": [ 334 | "\n", 335 | "1 A JFHJHJHHG " 336 | ] 337 | } 338 | ], 339 | "source": [ 340 | "#tuple\n", 341 | "result=map(uppercase,(1,'a','jfhjhjhhg'))\n", 342 | "print(type(result))\n", 343 | "print_upp(result)" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 55, 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "name": "stdout", 353 | "output_type": "stream", 354 | "text": [ 355 | "\n", 356 | "ABC DEF GHI " 357 | ] 358 | } 359 | ], 360 | "source": [ 361 | "#list\n", 362 | "result=map(uppercase,['abc','def','ghi'])\n", 363 | "print(type(result))\n", 364 | "print_upp(result)" 365 | ] 366 | }, 367 | { 368 | "cell_type": "code", 369 | "execution_count": 50, 370 | "metadata": {}, 371 | "outputs": [ 372 | { 373 | "name": "stdout", 374 | "output_type": "stream", 375 | "text": [ 376 | "\n", 377 | "('ABC', 'DEF', 'GHI')\n" 378 | ] 379 | } 380 | ], 381 | "source": [ 382 | "#list to tuple\n", 383 | "result=map(uppercase,['abc','def','ghi'])\n", 384 | "print(type(result))\n", 385 | "print(tuple(result))" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 51, 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "name": "stdout", 395 | "output_type": "stream", 396 | "text": [ 397 | "\n", 398 | "{'DEF', 'GHI', 'ABC'}\n" 399 | ] 400 | } 401 | ], 402 | "source": [ 403 | "result=map(uppercase,['abc','def','ghi'])\n", 404 | "print(type(result))\n", 405 | "print(set(result))" 406 | ] 407 | }, 408 | { 409 | "cell_type": "code", 410 | "execution_count": 52, 411 | "metadata": {}, 412 | "outputs": [ 413 | { 414 | "name": "stdout", 415 | "output_type": "stream", 416 | "text": [ 417 | "\n", 418 | "['ABC', 'DEF', 'GHI']\n" 419 | ] 420 | } 421 | ], 422 | "source": [ 423 | "result=map(uppercase,['abc','def','ghi'])\n", 424 | "print(type(result))\n", 425 | "print(list(result))" 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 53, 431 | "metadata": {}, 432 | "outputs": [ 433 | { 434 | "name": "stdout", 435 | "output_type": "stream", 436 | "text": [ 437 | "\n" 438 | ] 439 | }, 440 | { 441 | "ename": "TypeError", 442 | "evalue": "'NoneType' object is not callable", 443 | "output_type": "error", 444 | "traceback": [ 445 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 446 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 447 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'abc'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'def'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'ghi'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 448 | "\u001b[1;31mTypeError\u001b[0m: 'NoneType' object is not callable" 449 | ] 450 | } 451 | ], 452 | "source": [ 453 | "result=map(None,['abc','def','ghi'])\n", 454 | "print(type(result))\n", 455 | "print(list(result))" 456 | ] 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": null, 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "execution_count": null, 468 | "metadata": {}, 469 | "outputs": [], 470 | "source": [ 471 | "# filter:\n", 472 | "-filter () method filters the given iterable with the help of a given function\n", 473 | "- syntax:\n", 474 | " - filter(function,iterable)" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": 60, 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "data": { 484 | "text/plain": [ 485 | "['a', 'b']" 486 | ] 487 | }, 488 | "execution_count": 60, 489 | "metadata": {}, 490 | "output_type": "execute_result" 491 | } 492 | ], 493 | "source": [ 494 | "li=[1,2,'a','b',3]\n", 495 | "def isdigit(i):\n", 496 | " i=str(i)\n", 497 | " if i.isdigit():\n", 498 | " return False\n", 499 | " return i\n", 500 | "list(filter(isdigit,li))" 501 | ] 502 | }, 503 | { 504 | "cell_type": "code", 505 | "execution_count": 63, 506 | "metadata": {}, 507 | "outputs": [ 508 | { 509 | "name": "stdout", 510 | "output_type": "stream", 511 | "text": [ 512 | "a\n", 513 | "e\n", 514 | "i\n", 515 | "o\n" 516 | ] 517 | } 518 | ], 519 | "source": [ 520 | "alphabets=['a','b','c','d','e','f','g','h','i','o']\n", 521 | "def filtervowels(alphabet):\n", 522 | " vowels=['a','e','i','o','u']\n", 523 | " if (alphabet in vowels):\n", 524 | " return True\n", 525 | " else:\n", 526 | " return False\n", 527 | "result=filter(filtervowels,alphabets)\n", 528 | "#print(list(result))\n", 529 | "for i in result:\n", 530 | " print(i)" 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "execution_count": null, 536 | "metadata": {}, 537 | "outputs": [], 538 | "source": [ 539 | "-filter used to check whether given element is boolean or not" 540 | ] 541 | }, 542 | { 543 | "cell_type": "code", 544 | "execution_count": 67, 545 | "metadata": {}, 546 | "outputs": [ 547 | { 548 | "name": "stdout", 549 | "output_type": "stream", 550 | "text": [ 551 | "1\n", 552 | "a\n", 553 | "True\n", 554 | "0\n", 555 | "jhfghvhhjv\n" 556 | ] 557 | } 558 | ], 559 | "source": [ 560 | "r=[1,'a',0,True,'0',False,'jhfghvhhjv']\n", 561 | "result=filter(None,r)\n", 562 | "for i in result:\n", 563 | " print(i)" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": null, 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [] 572 | }, 573 | { 574 | "cell_type": "code", 575 | "execution_count": null, 576 | "metadata": {}, 577 | "outputs": [], 578 | "source": [ 579 | "#lambda:\n", 580 | "- python lambda is just a function without a name or anonymous function.\n", 581 | "#syn:\n", 582 | "lambda argument : expression\n", 583 | "- lambda takes 0 or more arguments but only one expression." 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 72, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "data": { 593 | "text/plain": [ 594 | "12" 595 | ] 596 | }, 597 | "execution_count": 72, 598 | "metadata": {}, 599 | "output_type": "execute_result" 600 | } 601 | ], 602 | "source": [ 603 | "#single argument\n", 604 | "r=lambda x:x*3\n", 605 | "r(4)" 606 | ] 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": 74, 611 | "metadata": {}, 612 | "outputs": [ 613 | { 614 | "data": { 615 | "text/plain": [ 616 | "65536" 617 | ] 618 | }, 619 | "execution_count": 74, 620 | "metadata": {}, 621 | "output_type": "execute_result" 622 | } 623 | ], 624 | "source": [ 625 | "#multiple argument\n", 626 | "r=lambda x,y:x**y\n", 627 | "r(4,8)" 628 | ] 629 | }, 630 | { 631 | "cell_type": "code", 632 | "execution_count": 75, 633 | "metadata": {}, 634 | "outputs": [ 635 | { 636 | "data": { 637 | "text/plain": [ 638 | "8" 639 | ] 640 | }, 641 | "execution_count": 75, 642 | "metadata": {}, 643 | "output_type": "execute_result" 644 | } 645 | ], 646 | "source": [ 647 | "# without arguments\n", 648 | "r=lambda :2**3\n", 649 | "r()" 650 | ] 651 | }, 652 | { 653 | "cell_type": "code", 654 | "execution_count": 76, 655 | "metadata": {}, 656 | "outputs": [ 657 | { 658 | "name": "stdout", 659 | "output_type": "stream", 660 | "text": [ 661 | "[1, 8, 27, 64, 125]\n" 662 | ] 663 | } 664 | ], 665 | "source": [ 666 | "#- lambda is not iterable.so by using map() or filter()\n", 667 | "result=map(lambda x:x**3,[1,2,3,4,5])\n", 668 | "print(list(result))" 669 | ] 670 | }, 671 | { 672 | "cell_type": "code", 673 | "execution_count": 78, 674 | "metadata": {}, 675 | "outputs": [ 676 | { 677 | "name": "stdout", 678 | "output_type": "stream", 679 | "text": [ 680 | "[20, 22, 24, 26, 28, 30, 32, 34, 36, 38]\n" 681 | ] 682 | } 683 | ], 684 | "source": [ 685 | "even=lambda n:n%2==0\n", 686 | "result=list(filter(even,range(20,40)))\n", 687 | "print(result)" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": 81, 693 | "metadata": {}, 694 | "outputs": [ 695 | { 696 | "name": "stdout", 697 | "output_type": "stream", 698 | "text": [ 699 | "[5, 7, 9]\n" 700 | ] 701 | } 702 | ], 703 | "source": [ 704 | "n1=[1,2,3]\n", 705 | "n2=[4,5,6]\n", 706 | "result=list(map(lambda x,y:(x+y),n1,n2))\n", 707 | "print(result)" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": 82, 713 | "metadata": {}, 714 | "outputs": [ 715 | { 716 | "name": "stdout", 717 | "output_type": "stream", 718 | "text": [ 719 | "sun\n", 720 | "wed\n", 721 | "fri\n", 722 | "sat\n" 723 | ] 724 | } 725 | ], 726 | "source": [ 727 | "w=['sun','tues','wed','thus','fri','sat']\n", 728 | "d=filter(lambda t:t if len(t)==3 else '',w)\n", 729 | "for i in d:\n", 730 | " print(i)" 731 | ] 732 | }, 733 | { 734 | "cell_type": "code", 735 | "execution_count": null, 736 | "metadata": {}, 737 | "outputs": [], 738 | "source": [ 739 | "filter(function,itearble)\n", 740 | "lambda argument:expression if \n", 741 | "lambda x:x if len(x)==3" 742 | ] 743 | }, 744 | { 745 | "cell_type": "code", 746 | "execution_count": null, 747 | "metadata": {}, 748 | "outputs": [], 749 | "source": [ 750 | "#task\n", 751 | "n1=['albert','james','nikola']\n", 752 | "n2=['einstein','watt','tesla']\n", 753 | "o/p:['Albert Einstein','James Watt','Nikola Tesla']\n", 754 | " (using lambda,map,list)" 755 | ] 756 | } 757 | ], 758 | "metadata": { 759 | "kernelspec": { 760 | "display_name": "Python 3", 761 | "language": "python", 762 | "name": "python3" 763 | }, 764 | "language_info": { 765 | "codemirror_mode": { 766 | "name": "ipython", 767 | "version": 3 768 | }, 769 | "file_extension": ".py", 770 | "mimetype": "text/x-python", 771 | "name": "python", 772 | "nbconvert_exporter": "python", 773 | "pygments_lexer": "ipython3", 774 | "version": "3.7.3" 775 | } 776 | }, 777 | "nbformat": 4, 778 | "nbformat_minor": 2 779 | } 780 | -------------------------------------------------------------------------------- /Python-Programming-Content.md: -------------------------------------------------------------------------------- 1 | # Python Programming 2 | 3 | ## Course Objectives 4 | The course is designed to provide Basic knowledge of Python. Python programming is intended for software engineers, system analysts, program managers and user support personnel who wish to learn the Python programming language. 5 | 6 | ## Introduction 7 | The Python program is a scripting language that can be used for development, coding websites and applications, processing images, scientific data, and more. The program can be found in action on the Google search engine, NASA, Disney, Pinterest, and more. It was built for ease of use and speed and is less complicated than Ruby and other similar object-oriented programming languages. Because it is open-sourced, the program has enjoyed popularity among developers and programmers, and it continues to be the base program for most websites in operation on the internet today. 8 | 9 | Python software is free to download and can be accessed on virtually every type of operating system. It comes with a large standard library that will make programming simple tasks, such as reading and modifying files, connecting to web servers, and more, easy. companies such as Nokia, IBM, Google, and Disney were all searching for programmers with Python experience to help them with web applications and framework development; in this respect, Python works perfectly with Django, which functions as the base framework system that Python builds on. Python also enables programs to script professional-grade web-based products. From back-end to front-end development, full-stack, and web-based options, Python programmers continue to find more economic prospects as the use of the language grows to encompass all areas of 10 | software and web development. 11 | 12 | ## Duration 13 | - 6 Days (or) 36 Hours. 14 | 15 | ## Table of Contents 16 | |S.No|Topics| 17 | |-----|----| 18 | |1|Python Introduction| 19 | |2|Literate Programming | 20 | |3|Jupyter Notebook Environment| 21 | |4|Markdown format for documentation| 22 | |5|Python basics | 23 | |6|Keywords in Python,Operators in Python | 24 | |7|Conditional Statements | 25 | |8|Iterations| 26 | |9|Jump Statements (Break, Continue with examples)| 27 | |10|continue (with example)| 28 | |11|Functions| 29 | |12|Arguements in Functions | 30 | |13|Strings| 31 | |14|String Functions,String Slicing| 32 | |15|Python Data Structures| 33 | |16|Lists| 34 | |17|List Methods | 35 | |18|Tuples| 36 | |19|Tuple Methods | 37 | |20|Dictionaries| 38 | |21|Dictionary Methods | 39 | |22|Sets| 40 | |23|Set Methods | 41 | |24|Packages and Modules| 42 | |25|Regular Expression | 43 | |26|File Handling| 44 | |27|List Comprehension | 45 | |28|Iterators, Generators | 46 | |29|Functional Programming| 47 | |30|Maps, Filters, Lambda | 48 | |31|Object-Oriented Programming| 49 | |32|Classes, Objects, Constructors, inheritence| 50 | |33|Python Packages and modules using oop's| 51 | |34|Python Libraries for Data Science| 52 | |35|NumPy, Nd arrays, Advantages of NumPy| 53 | |36|Pandas| 54 | |37|Data Structures in Pandas,Pandas Series| 55 | |38|Data Frames| 56 | |39|Data Visualisation using Matplotlib library | 57 | 58 | 59 | ## Learning Outcome 60 | 61 | Problem-solving and programming capability 62 | 63 | ## Entry Requirements (Pre-requisites) 64 | Basic Knowledge of Computer 65 | 66 | ## Eligibility 67 | Who are willing to Learn Python Programming language are eligible. 68 | 69 | ## Hardware Requirements: 70 | - i3 or above Processor is required 71 | - 4 GB or above RAM is recommended 72 | - Good Internet Connectivity 73 | - OS-Windows 10 is Preferable 74 | -------------------------------------------------------------------------------- /Resources.md: -------------------------------------------------------------------------------- 1 | # Python Resource 2 | * Duration : 20-june-2020 to 11-july-2020 3 | * Timings : 10 AM to 12 PM 4 | 5 | 6 | ## Python ipnb files 7 | ![Git_link](https://github.com/AP-Skill-Development-Corporation/APSSDC-Student-PythonTeam3) 8 | 9 | ## Recorded Sessions 10 | ![Drive_Link](https://drive.google.com/drive/folders/1cbSKm8ih9TAwUVNtLs_4rtVPRO62N3Uj) 11 | 12 | ## Python Reference Material 13 | ![Github_link](https://github.com/LavanyaPolamarasetty/Python_syllabus/tree/master/Python_Syllabus) 14 | 15 | ## Python Keywords in details 16 | ![website_Link](https://www.programiz.com/python-programming/keyword-list) 17 | 18 | ## Markdown Syntax 19 | ![Markdown_Link](https://www.markdownguide.org/cheat-sheet/) 20 | 21 | ## Regular Expression 22 | ![Website_link](https://www.programiz.com/python-programming/regex) 23 | 24 | ## Python Coding Probelms with solutions 25 | ![git_link](https://github.com/ProgrammingHero1/100-plus-python-coding-problems-with-solutions) 26 | 27 | ## Free Certification Courses 28 | ![Blog_link](https://Bit.ly/free-certification) 29 | 30 | -------------------------------------------------------------------------------- /data.csv: -------------------------------------------------------------------------------- 1 | Name,College,Course,Branch,Year 2 | Ambika, ,Python,ECE,2017 3 | Pavani,GITAM,Gaming,CSE,2017 4 | Archana,GEC,Cyber Security,CSE,2016 5 | Poojitha,VVIT, ,ECE,2018 6 | Ambika, ,Python,ECE,2017 7 | Pavani,GITAM,Gaming,CSE,2017 8 | Archana,GEC,Cyber Security,CSE,2016 9 | Poojitha,VVIT, ,ECE,2018 10 | Archana,GEC,Cyber Security,,2016 11 | Poojitha,VVIT,,ECE,2018 -------------------------------------------------------------------------------- /package/mobile.py: -------------------------------------------------------------------------------- 1 | def vivo(): 2 | print("Features :") 3 | print("Battery : 5000mhg \n RAM : 6GB \n cost : 12000rs ") 4 | 5 | def realme(): 6 | print("Features :") 7 | print("Battery : 5500mhg \n RAM : 32GB \n cost : 10000rs ") --------------------------------------------------------------------------------