From 4a735f833653551e3321fbe9a8e47faa879d282f Mon Sep 17 00:00:00 2001 From: kinitrupti Date: Thu, 15 Oct 2015 17:40:30 +0530 Subject: solved errors --- .../.ipynb_checkpoints/chapter12-checkpoint.ipynb | 1504 +++++++++++++++++ ANSI_C_Programming/chapter12.ipynb | 56 +- .../.ipynb_checkpoints/Chapter1-checkpoint.ipynb | 334 ++++ .../.ipynb_checkpoints/Chapter11-checkpoint.ipynb | 631 +++++++ A_Heat_Transfer_Text_Book/Chapter1.ipynb | 664 ++++---- A_Heat_Transfer_Text_Book/Chapter11.ipynb | 1266 +++++++------- .../.ipynb_checkpoints/ch10-checkpoint.ipynb | 642 +++++++ Beginning_C++_Through_Game_Programming/ch10.ipynb | 81 +- Beginning_C_By_Ivon_Horton/chapter13.ipynb | 10 +- .../.ipynb_checkpoints/chapter13-checkpoint.ipynb | 412 +++++ .../.ipynb_checkpoints/chapter5-checkpoint.ipynb | 488 ++++++ .../.ipynb_checkpoints/chapter9-checkpoint.ipynb | 1033 ++++++++++++ .../chapter13.ipynb | 13 +- .../chapter5.ipynb | 27 +- .../chapter9.ipynb | 65 +- .../students.dat | 0 .../.ipynb_checkpoints/ch1-checkpoint.ipynb | 261 +++ .../.ipynb_checkpoints/ch10-checkpoint.ipynb | 490 ++++++ .../.ipynb_checkpoints/ch12-checkpoint.ipynb | 355 ++++ .../.ipynb_checkpoints/ch13-checkpoint.ipynb | 350 ++++ .../.ipynb_checkpoints/ch15-checkpoint.ipynb | 611 +++++++ .../.ipynb_checkpoints/ch2-checkpoint.ipynb | 249 +++ .../ch1.ipynb | 39 +- .../ch10.ipynb | 67 +- .../ch12.ipynb | 22 +- .../ch13.ipynb | 18 +- .../ch15.ipynb | 38 +- .../ch2.ipynb | 19 +- .../.ipynb_checkpoints/chapter2_2-checkpoint.ipynb | 814 +++++++++ Engineering_Physics_Vijaya/chapter2_2.ipynb | 17 +- .../ch15.ipynb | 135 +- .../.ipynb_checkpoints/chapter1-checkpoint.ipynb | 169 ++ Mastering_C/chapter1.ipynb | 13 +- .../Chapter13_4-checkpoint.ipynb | 340 ++++ Power_Electronics_by_P_S_Bimbhra/Chapter13_4.ipynb | 680 ++++---- .../Chapter_14_1-checkpoint.ipynb | 175 ++ .../Chapter_15_1-checkpoint.ipynb | 351 ++++ Practical_C_Programming/Chapter_14_1.ipynb | 30 +- Practical_C_Programming/Chapter_15_1.ipynb | 72 +- Practical_C_Programming/numbers.dat | 1 + Practical_C_Programming/numbers.dat~ | 0 .../chapter22.ipynb | 94 ++ .../.ipynb_checkpoints/chapter13-checkpoint.ipynb | 266 +++ Programming_With_Java_A_Primer/chapter13.ipynb | 25 +- Programming_With_Java_A_Primer/chapter17.ipynb | 10 +- .../.ipynb_checkpoints/Chapter_16-checkpoint.ipynb | 294 ++++ Programming_in_C/Chapter_16.ipynb | 26 +- Schaum's_Outline/README.txt | 10 + Schaum's_Outline/ch1.ipynb | 448 +++++ Schaum's_Outline/ch10.ipynb | 877 ++++++++++ Schaum's_Outline/ch11.ipynb | 793 +++++++++ Schaum's_Outline/ch12.ipynb | 869 ++++++++++ Schaum's_Outline/ch13.ipynb | 426 +++++ Schaum's_Outline/ch14.ipynb | 616 +++++++ Schaum's_Outline/ch2.ipynb | 740 +++++++++ Schaum's_Outline/ch3.ipynb | 1153 +++++++++++++ Schaum's_Outline/ch4.ipynb | 1633 ++++++++++++++++++ Schaum's_Outline/ch5.ipynb | 1746 ++++++++++++++++++++ Schaum's_Outline/ch6.ipynb | 1276 ++++++++++++++ Schaum's_Outline/ch7.ipynb | 750 +++++++++ Schaum's_Outline/ch8.ipynb | 1064 ++++++++++++ Schaum's_Outline/ch9.ipynb | 444 +++++ Schaum's_Outline/screenshots/ratio.png | Bin 0 -> 46696 bytes Schaum's_Outline/screenshots/swap.png | Bin 0 -> 37083 bytes Schaum's_Outline/screenshots/vector.png | Bin 0 -> 40040 bytes Schaum's_Outlines:_Programming_with_C++/README.txt | 10 - Schaum's_Outlines:_Programming_with_C++/ch1.ipynb | 448 ----- Schaum's_Outlines:_Programming_with_C++/ch10.ipynb | 877 ---------- Schaum's_Outlines:_Programming_with_C++/ch11.ipynb | 793 --------- Schaum's_Outlines:_Programming_with_C++/ch12.ipynb | 869 ---------- Schaum's_Outlines:_Programming_with_C++/ch13.ipynb | 426 ----- Schaum's_Outlines:_Programming_with_C++/ch14.ipynb | 616 ------- Schaum's_Outlines:_Programming_with_C++/ch2.ipynb | 740 --------- Schaum's_Outlines:_Programming_with_C++/ch3.ipynb | 1153 ------------- Schaum's_Outlines:_Programming_with_C++/ch4.ipynb | 1633 ------------------ Schaum's_Outlines:_Programming_with_C++/ch5.ipynb | 1746 -------------------- Schaum's_Outlines:_Programming_with_C++/ch6.ipynb | 1276 -------------- Schaum's_Outlines:_Programming_with_C++/ch7.ipynb | 750 --------- Schaum's_Outlines:_Programming_with_C++/ch8.ipynb | 1064 ------------ Schaum's_Outlines:_Programming_with_C++/ch9.ipynb | 444 ----- .../screenshots/ratio.png | Bin 46696 -> 0 bytes .../screenshots/swap.png | Bin 37083 -> 0 bytes .../screenshots/vector.png | Bin 40040 -> 0 bytes 83 files changed, 24412 insertions(+), 14535 deletions(-) create mode 100755 ANSI_C_Programming/.ipynb_checkpoints/chapter12-checkpoint.ipynb create mode 100755 A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter1-checkpoint.ipynb create mode 100755 A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter11-checkpoint.ipynb create mode 100755 Beginning_C++_Through_Game_Programming/.ipynb_checkpoints/ch10-checkpoint.ipynb create mode 100755 C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter13-checkpoint.ipynb create mode 100755 C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter5-checkpoint.ipynb create mode 100755 C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter9-checkpoint.ipynb create mode 100644 C++_Demystified:_A_Self-Teaching_Guide/students.dat create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch1-checkpoint.ipynb create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch10-checkpoint.ipynb create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch12-checkpoint.ipynb create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch13-checkpoint.ipynb create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch15-checkpoint.ipynb create mode 100755 C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch2-checkpoint.ipynb create mode 100755 Engineering_Physics_Vijaya/.ipynb_checkpoints/chapter2_2-checkpoint.ipynb create mode 100755 Mastering_C/.ipynb_checkpoints/chapter1-checkpoint.ipynb create mode 100755 Power_Electronics_by_P_S_Bimbhra/.ipynb_checkpoints/Chapter13_4-checkpoint.ipynb create mode 100755 Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb create mode 100755 Practical_C_Programming/.ipynb_checkpoints/Chapter_15_1-checkpoint.ipynb create mode 100644 Practical_C_Programming/numbers.dat create mode 100644 Practical_C_Programming/numbers.dat~ create mode 100755 Principles_Of_Electronic_Communication_Systems_by_L_E_Frenze/chapter22.ipynb create mode 100755 Programming_With_Java_A_Primer/.ipynb_checkpoints/chapter13-checkpoint.ipynb create mode 100755 Programming_in_C/.ipynb_checkpoints/Chapter_16-checkpoint.ipynb create mode 100755 Schaum's_Outline/README.txt create mode 100755 Schaum's_Outline/ch1.ipynb create mode 100755 Schaum's_Outline/ch10.ipynb create mode 100755 Schaum's_Outline/ch11.ipynb create mode 100755 Schaum's_Outline/ch12.ipynb create mode 100755 Schaum's_Outline/ch13.ipynb create mode 100755 Schaum's_Outline/ch14.ipynb create mode 100755 Schaum's_Outline/ch2.ipynb create mode 100755 Schaum's_Outline/ch3.ipynb create mode 100755 Schaum's_Outline/ch4.ipynb create mode 100755 Schaum's_Outline/ch5.ipynb create mode 100755 Schaum's_Outline/ch6.ipynb create mode 100755 Schaum's_Outline/ch7.ipynb create mode 100755 Schaum's_Outline/ch8.ipynb create mode 100755 Schaum's_Outline/ch9.ipynb create mode 100755 Schaum's_Outline/screenshots/ratio.png create mode 100755 Schaum's_Outline/screenshots/swap.png create mode 100755 Schaum's_Outline/screenshots/vector.png delete mode 100755 Schaum's_Outlines:_Programming_with_C++/README.txt delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch1.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch10.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch11.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch12.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch13.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch14.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch2.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch3.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch4.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch5.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch6.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch7.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch8.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/ch9.ipynb delete mode 100755 Schaum's_Outlines:_Programming_with_C++/screenshots/ratio.png delete mode 100755 Schaum's_Outlines:_Programming_with_C++/screenshots/swap.png delete mode 100755 Schaum's_Outlines:_Programming_with_C++/screenshots/vector.png diff --git a/ANSI_C_Programming/.ipynb_checkpoints/chapter12-checkpoint.ipynb b/ANSI_C_Programming/.ipynb_checkpoints/chapter12-checkpoint.ipynb new file mode 100755 index 00000000..59c2b543 --- /dev/null +++ b/ANSI_C_Programming/.ipynb_checkpoints/chapter12-checkpoint.ipynb @@ -0,0 +1,1504 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a886cf212382fa732d2b3df088bbcba9a65ba4a31cbe899c80e912ac04c2747f" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 12:FILE INPUT/OUTPUT" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:391" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "fp=open('PR1.txt','r') #open the file for reading\n", + "ch=fp.readlines() #ch will store all content of file\n", + "print \"%s\" % (' '.join(ch)) #prints content of file\n", + "print \"\\n\"\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "site:http://www.bzu.edu.pk/\n", + " user:siteuser@localhost\n", + " version:5.5.32-0ubuntu0.12.04.1\n", + " db: bzu\n", + " tables:\n", + " username:web,webadmin,webadministrator23\n", + " pass:71dc9f7af599450b23a3b5d54bc665c7,\t49fa1a081c8d5c8dcfa05d730803251a,\t*E8665C4049F515D836A3C8704D0543C6DA0FE96D\n", + "\n", + "\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:394" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "try:\n", + " fp=open('yoyo.txt','r')\n", + " for line in fin:\n", + " print line\n", + " fp.close()\n", + "except:\n", + " print 'cannot open file'" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "cannot open file\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:395" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "nol=0\n", + "nom=0\n", + "nob=0\n", + "noc=0\n", + "fp=open('H4CK3R.txt','r')\n", + "while True:\n", + " ch=fp.read(1)\n", + " if not ch:\n", + " break\n", + " noc+=1\n", + " if ch==' ':\n", + " nob+=1\n", + " if ch=='\\n':\n", + " nol+=1\n", + " if ch=='\\t':\n", + " nom+=1\n", + "fp.close()\n", + "print \"\\n\"\n", + "fp.close()\n", + "print \"Number of characters=%d\\n\" % (noc)\n", + "print \"Number of blanks=%d\\n\" % (nob)\n", + "print \"Number of tabs=%d\\n\" % (nom)\n", + "print \"Number of lines=%d\\n\" % (nol)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "\n", + "Number of characters=162\n", + "\n", + "Number of blanks=21\n", + "\n", + "Number of tabs=3\n", + "\n", + "Number of lines=4\n", + "\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:396-397" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import sys\n", + "try:\n", + " fs=open('H4CK3R.txt','r')\n", + "except:\n", + " print \"Cannot open file\"\n", + " sys.exit(1)\n", + "try:\n", + " ft=open('python.txt','w')\n", + "except:\n", + " print \"Cannot open file\"\n", + " fs.close()\n", + " sys.exit(2)\n", + "ch=fs.readlines()\n", + "ft.writelines(ch)\n", + "fs.close()\n", + "ft.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "SystemExit", + "evalue": "1", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Cannot open file\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:399" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "try:\n", + " fp=open('POEM.txt','w')\n", + "except:\n", + " print 'cannot open file'\n", + "print \"\\nEnter a few lines of text:\\n\"\n", + "s=' '\n", + "while (len(s)>0):\n", + " s=raw_input()\n", + " fp.writelines(s)\n", + " fp.writelines(\"\\n\")\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter a few lines of text:\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Shining and bright,they are forever,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "so true about diamonds,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "more so of memories,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "especially yours!\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:400" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "try:\n", + " fp=open('POEM.txt','r')\n", + "except:\n", + " print 'cannot open file'\n", + "s=fp.read(99)\n", + "print \"%s\" % (s)\n", + "print \"\\n\"\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Shining and bright,they are forever,\n", + "so true about diamonds,\n", + "more so of memories,\n", + "especially yours!\n", + "\n", + "\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:401-402" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "class emp():\n", + " def __init__(self,**kwds):\n", + " self.__dict__.update(kwds)\n", + "another='Y'\n", + "e=emp()\n", + "try:\n", + " fp=open('EMPLOYEE.txt','w')\n", + "except:\n", + " print 'cannot open file'\n", + "while another=='Y':\n", + " print \"\\nEnter name,age and basic salary:\"\n", + " e.name=raw_input()\n", + " e.age=eval(raw_input())\n", + " e.bs=eval(raw_input())\n", + " ch=\"%s %d %f\" % (e.name,e.age,e.bs)\n", + " fp.writelines(ch)\n", + " fp.writelines(\"\\n\")\n", + " print \"Add another record(Y/N)\"\n", + " another=raw_input()\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sunil\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "34\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1250.50\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sameer\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1300.50\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Rahul\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "34\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1400.55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "n\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:403-404" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "class emp():\n", + " def __init__(self,**kwds):\n", + " self.__dict__.update(kwds)\n", + "e=emp()\n", + "try:\n", + " fp=open('EMPLOYEE.txt','r') # open the file for reading\n", + "except:\n", + " print 'cannot open file'\n", + "for line in fp: # iterate over each line\n", + " e.name, e.age, e.bs = line.split() # split it by whitespace\n", + " e.age = int(e.age) # convert age from string to int\n", + " e.bs = float(e.bs) # convert bs from string to float\n", + " print \"%s %d %f\\n\" %(e.name, e.age, e.bs)\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Sunil 34 1250.500000\n", + "\n", + "Sameer 21 1300.500000\n", + "\n", + "Rahul 34 1400.550000\n", + "\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:404-405" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import sys #for exit()\n", + "try:\n", + " fs=open('H4CK3R.txt','rb') # open the file for reading\n", + "except:\n", + " print 'cannot open file'\n", + " sys.exit(1)\n", + "try:\n", + " ft=open('python.txt','wb') # open the file for writing\n", + "except:\n", + " print 'cannot open file'\n", + " fs.close()\n", + " sys.exit(2)\n", + "ch=fs.readlines()\n", + "ft.writelines(ch)\n", + "fs.close()\n", + "ft.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "SystemExit", + "evalue": "1", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "cannot open file\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:407-408" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "class emp():\n", + " def __init__(self,**kwds):\n", + " self.__dict__.update(kwds)\n", + "another='Y'\n", + "e=emp()\n", + "try:\n", + " fp=open('EMP.txt','wb') # open the file for reading\n", + "except:\n", + " print 'cannot open file' \n", + "while another=='Y':\n", + " print \"\\nEnter name,age and basic salary:\"\n", + " e.name=raw_input()\n", + " e.age=eval(raw_input())\n", + " e.bs=eval(raw_input())\n", + " ch=\"%s %d %f\" % (e.name,e.age,e.bs)\n", + " fp.writelines(ch)\n", + " print \"Add another record (Y/N)\"\n", + " another=raw_input()\n", + " if another=='Y':\n", + " fp.writelines(\"\\n\")\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "24\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1250.50\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record (Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ranjan\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1300.60\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record (Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Harish\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "28\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1400.70\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record (Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:409" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "class emp():\n", + " def __init__(self,**kwds):\n", + " self.__dict__.update(kwds)\n", + "e=emp()\n", + "try:\n", + " fp=open('EMP.txt','rb')\n", + "except:\n", + " print \"Cannot open file\"\n", + "for line in fp:\n", + " e.name, e.age, e.bs = line.split() # split it by whitespace\n", + " e.age = int(e.age) # convert age from string to int\n", + " e.bs = float(e.bs) # convert bs from string to float\n", + " print \"%s %d %f\\n\" %(e.name, e.age, e.bs)\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\n", + "\n", + "Ranjan 21 1300.600000\n", + "\n", + "Harish 28 1400.700000\n", + "\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:411-414" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "class emp():\n", + " def __init__(self,**kwds):\n", + " self.__dict__.update(kwds)\n", + "e=emp()\n", + "try:\n", + " fp=open('EMP.txt','rb+') # open the file for reading\n", + "except:\n", + " try:\n", + " fp=open('EMP.txt','wb+') # open the file for writing\n", + " except:\n", + " print 'cannot open file'\n", + "while 1:\n", + " print \"1.Add Records\"\n", + " print \"2.List Records\"\n", + " print \"3.Modify Records\"\n", + " print \"4.Delete Records\"\n", + " print \"0.Exit\"\n", + " print \"Your choice\"\n", + " choice=eval(raw_input())\n", + " def add():\n", + " import os\n", + " fp.seek(0,os.SEEK_END)\n", + " another='Y'\n", + " while another=='Y':\n", + " print \"\\nEnter name,age and basic salary:\"\n", + " e.name=raw_input()\n", + " e.age=eval(raw_input())\n", + " e.bs=eval(raw_input())\n", + " ch=\"%s %d %f\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\" % (e.name,e.age,e.bs)\n", + " fp.writelines(\"\\n\")\n", + " fp.writelines(ch)\n", + " print \"Add another record(Y/N)\"\n", + " another=raw_input()\n", + " def list():\n", + " import os\n", + " fp.seek(0,os.SEEK_SET)\n", + " for line in fp: # iterate over each line\n", + " if len(line)>10:\n", + " e.name, e.age, e.bs = line.split() # split it by whitespace\n", + " e.age = int(e.age) # convert age from string to int\n", + " e.bs = float(e.bs) # convert bs from string to float\n", + " print \"%s %d %f\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\" %(e.name, e.age, e.bs)\n", + " def modify():\n", + " another='Y'\n", + " while another=='Y':\n", + " print \"\\nEnter name of employee to modify\"\n", + " empname=raw_input()\n", + " import os\n", + " fp.seek(0,os.SEEK_SET)\n", + " for line in iter(fp.readline, ''):\n", + " if len(line)>10:\n", + " e.name, e.age, e.bs=line.split()\n", + " e.age = int(e.age) # convert age from string to int\n", + " e.bs = float(e.bs)\n", + " if(cmp(e.name,empname)==0):\n", + " c=len(line)\n", + " print \"\\nEnter new name,age & bs\"\n", + " e.name=raw_input()\n", + " e.age=eval(raw_input())\n", + " e.bs=eval(raw_input())\n", + " import os\n", + " fp.seek(-c,os.SEEK_CUR)\n", + " ch=\"%s %d %f\" % (e.name,e.age,e.bs)\n", + " fp.writelines(\"\\n\")\n", + " fp.writelines(ch)\n", + " fp.writelines(\"\\n\")\n", + " break\n", + " print \"\\nModify another Record(Y/N)\"\n", + " another=raw_input()\n", + " def delete():\n", + " another='Y'\n", + " global fp\n", + " while another=='Y':\n", + " print \"\\nEnter name of employee to delete\"\n", + " empname=raw_input()\n", + " ft=open('TEMP.txt','wb')\n", + " import os\n", + " fp.seek(0,os.SEEK_SET)\n", + " for line in fp:\n", + " if len(line)>10:\n", + " e.name, e.age, e.bs=line.split()\n", + " e.age = int(e.age) # convert age from string to int\n", + " e.bs = float(e.bs)\n", + " if(cmp(e.name,empname)!=0):\n", + " ch=\"%s %d %f\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\" % (e.name,e.age,e.bs)\n", + " ft.writelines(ch)\n", + " ft.writelines(\"\\n\")\n", + " fp.close()\n", + " ft.close()\n", + " import os\n", + " os.remove(\"EMP.txt\") # Delete file EMP.txt\n", + " os.rename( \"TEMP.txt\", \"D:/EMP.txt\" ) # Rename a file from TEMP.txt to EMP.txt\n", + " fp=open('EMP.txt','rb+')\n", + " print \"Delete another record(Y/N)\"\n", + " another=raw_input()\n", + " def exit():\n", + " import sys\n", + " fp.close()\n", + " sys.exit(0)\n", + " def switch(c):\n", + " return {1: add,\n", + " 2: list,\n", + " 3: modify,\n", + " 4: delete,\n", + " 0: exit,\n", + " }[c]()\n", + " switch(choice)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\t\t\t\t\t\t\t\t\t\t\n", + "Ranjan 21 1300.600000\t\t\t\t\t\t\t\t\t\t\n", + "Harish 28 1400.700000\t\t\t\t\t\t\t\t\t\t\n", + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ram\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5000\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name,age and basic salary:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "GOPAL\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "19\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6755.5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Add another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\t\t\t\t\t\t\t\t\t\t\n", + "Ranjan 21 1300.600000\t\t\t\t\t\t\t\t\t\t\n", + "Harish 28 1400.700000\t\t\t\t\t\t\t\t\t\t\n", + "Ram 20 5000.000000\t\t\t\t\t\t\t\t\t\t\n", + "GOPAL 19 6755.500000\t\t\t\t\t\t\t\t\t\t\n", + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name of employee to modify\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ram\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter new name,age & bs\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Radhey\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "15\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4687.66\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Modify another Record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\t\t\t\t\t\t\t\t\t\t\n", + "Ranjan 21 1300.600000\t\t\t\t\t\t\t\t\t\t\n", + "Harish 28 1400.700000\t\t\t\t\t\t\t\t\t\t\n", + "Radhey 15 4687.660000\t\t\t\t\t\t\t\t\t\t\n", + "GOPAL 19 6755.500000\t\t\t\t\t\t\t\t\t\t\n", + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name of employee to delete\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Radhey\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Delete another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\t\t\t\t\t\t\t\t\t\t\n", + "Ranjan 21 1300.600000\t\t\t\t\t\t\t\t\t\t\n", + "Harish 28 1400.700000\t\t\t\t\t\t\t\t\t\t\n", + "GOPAL 19 6755.500000\t\t\t\t\t\t\t\t\t\t\n", + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter name of employee to delete\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "GOPAL\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Delete another record(Y/N)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "N\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Suresh 24 1250.500000\t\t\t\t\t\t\t\t\t\t\n", + "Ranjan 21 1300.600000\t\t\t\t\t\t\t\t\t\t\n", + "Harish 28 1400.700000\t\t\t\t\t\t\t\t\t\t\n", + "1.Add Records\n", + "2.List Records\n", + "3.Modify Records\n", + "4.Delete Records\n", + "0.Exit\n", + "Your choice\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "ename": "SystemExit", + "evalue": "0", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:416-417" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "from StringIO import StringIO\n", + "buffer = StringIO()\n", + "print \"\\nEnter source file name\"\n", + "source=raw_input()\n", + "try:\n", + " inhandle=open(source,'rb')\n", + "except:\n", + " print \"Cannot open file\"\n", + "print \"Enter target file name\"\n", + "target=raw_input()\n", + "try:\n", + " outhandle=open(target,'wb')\n", + "except:\n", + " print \"Cannot open file\"\n", + " inhandle.close()\n", + "bytes=inhandle.readlines()\n", + "buffer.write(bytes)\n", + "outhandle.writelines(buffer.getvalue())\n", + "buffer.close()\n", + "inhandle.close()\n", + "outhandle.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Enter source file name\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "H4CK3R.txt\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter target file name\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "python.txt\n" + ] + } + ], + "prompt_number": 24 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/ANSI_C_Programming/chapter12.ipynb b/ANSI_C_Programming/chapter12.ipynb index 8bab1a13..59c2b543 100755 --- a/ANSI_C_Programming/chapter12.ipynb +++ b/ANSI_C_Programming/chapter12.ipynb @@ -181,8 +181,32 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 13 + "outputs": [ + { + "ename": "SystemExit", + "evalue": "1", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Cannot open file\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 1 }, { "cell_type": "heading", @@ -563,8 +587,32 @@ ], "language": "python", "metadata": {}, - "outputs": [], - "prompt_number": 20 + "outputs": [ + { + "ename": "SystemExit", + "evalue": "1", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "cannot open file\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 2 }, { "cell_type": "heading", diff --git a/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter1-checkpoint.ipynb b/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter1-checkpoint.ipynb new file mode 100755 index 00000000..dd1cacc1 --- /dev/null +++ b/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter1-checkpoint.ipynb @@ -0,0 +1,334 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1 - \"Introduction\"" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.1, Page number: 13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "k=35; #Thermal Conductivity, [W/m*K]\n", + "T1=110 # Temperature of front[C]\n", + "T2=50; # Temperature of back,[C]\n", + "A=0.4 #area of slab,[m**2]\n", + "x=0.03; #Thickness of slab,[m]\n", + "\n", + "#Calculations\n", + "q=-k*(T2-T1)/(1000*x); #formula for heat flux[KW/m^2]\n", + "Q=q*A; #formula for heat transfer rate[KW]\n", + "\n", + "#Results\n", + "print \"Heat flux is:\",q,\"KW/m^2\\n\"\n", + "print \"Heat transfer rate is:\",Q,\"KW \\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Heat flux is: 70.0 KW/m^2\n", + "\n", + "Heat transfer rate is: 28.0 KW \n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.2, Page number: 16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "k1=372; # Thermal Conductivity of slab,W/m*K\n", + "x1=0.003; # Thickness of slab,m\n", + "x2=0.002 # Thickness of steel,m\n", + "k2=17; # Thermal Conductivity of steel,W/m*K\n", + "T1=400; # Temperature on one side,C\n", + "T2=100 #Temperature on other side,C\n", + "\n", + "#Calculations\n", + "Tcu=solve(x+2*x*(k1/x1)*(x2/k2)-(T1-T2),x);\n", + "#q=k1*(Tcu/x1)=k2*(Tss/x2);\n", + "Tss = Tcu[0]*(k1/x1)*(x2/k2); # formula for temperature gradient in steel side\n", + "Tcul=T1-Tss;\n", + "Tcur=T2+Tss;\n", + "q=k2*Tss/(1000*x2); # formula for heat conducted, kW\\m^2\n", + "\n", + "#Results\n", + "print \"Temperature on left copper side is :\",round(Tcul,3),\"C\\n\"\n", + "print \"Temperature on right copper side is :\",round(Tcur,3),\"C\\n\"\n", + "print \"Heat conducted through the wall is :\",round(q,3),\"kW\\m^2\\n\"\n", + "print \"Our initial approximation was accurate within a few percent.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature on left copper side is : 254.971 C\n", + "\n", + "Temperature on right copper side is : 245.029 C\n", + "\n", + "Heat conducted through the wall is : 1232.749 kW\\m^2\n", + "\n", + "Our initial approximation was accurate within a few percent.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.3, Page number: 22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "q1=6000; #Heat flux, W*m**-2\n", + "T1=120; #Heater Temperature, C\n", + "T2=70; #final Temperature of Heater, C\n", + "q2=2000; #final heat flux, W*m**-2\n", + "\n", + "#Calculations\n", + "h=q1/(T1-T2) #formula for average heat transfer cofficient\n", + "Tnew=T2+q2/h; #formula for new Heater temperature, C\n", + "\n", + "#Results\n", + "print \"Average Heat transfer coefficient is:\",h,\"W/(m^2*K)\\n\"\n", + "print \"New Heater Temperature is:\",round(Tnew,3),\"C\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average Heat transfer coefficient is: 120.0 W/(m^2*K)\n", + "\n", + "New Heater Temperature is: 86.667 C\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.4, Page number: 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "from numpy import linspace\n", + "import matplotlib.pyplot as plt\n", + "from pylab import *\n", + "%matplotlib inline\n", + "\n", + "#Variables\n", + "h=250; #Heat Transfer Coefficient, W/(m**2*K)\n", + "k=45; #Thermal Conductivity, W/(m*K)\n", + "c=180; #Heat Capacity, J/(kg*K)\n", + "a=9300; #density, kg/m**3\n", + "T1=200; #temperature, C\n", + "D=0.001; #diameter of bead, m\n", + "t1=linspace(0,5,50); #defining time interval of 0.1 seconds\n", + "T=linspace(0,5,50);\n", + "i=0;\n", + "\n", + "#Calculations\n", + "while i<50:\n", + " T[i]=T1-c*math.exp(-t1[i]/((a*c*D)/(6*h))); #Calculating temperature at each time in degree C\n", + " i=i+1;\n", + "\n", + "plt.plot(t1,T);\n", + "plt.xlabel(\"Time(in sec)\");\n", + "plt.ylabel(\"Temperature(in degree C)\");\n", + "plt.title(\"Thermocouple response to a hot gas flow\");\n", + "plt.show();\n", + "\n", + "Bi = h*(D/2)/k; #biot no.\n", + "\n", + "#Results\n", + "print \"The value of Biot no for this thermocouple is\",round(Bi,5);\n", + "print \"Bi is <0.1 and hence the thermocouple could be considered as a lumped heat capacity system and the assumption taken is valid.\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhE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//79/P7779SuXZuN\nGzdy8uRJoqOj2b9/P3v37mXbtm0cOXKEd999l4iICA4cOMCSJUuM+/H19WXr1q1leJZEdWJl7gCE\nMAcLCwsGDx6MpaUlbdu2JT8/n4EDBwLQrl074uPjiY2N5ciRI8Y7AYPBgJOTEwBnzpwxjiJ5u5o1\na/LII48A0LFjRzZt2nTHZ3r06MH06dN54oknGDFiBM7OzmzcuJGNGzcaB6W7du0aJ0+e5Nq1awQE\nBBgnvLl1ciQnJydOnz5torMiqjtJCKLaqlmzJqDNI2BtbW1cX6NGDfLy8lBK0aZNG3bs2FHo9vn5\n+YWuL2xft5sxYwZDhgzhp59+okePHvz6668AzJw5k2eeeabAZ5ctW1bkuP5KqWo9eJswLSkyEtVS\nadpStGrViosXL7Jz505Am3shJiYGgGbNmhnrE+7FqVOnaNOmDa+++iqdO3fm+PHjDBw4kFWrVhnr\nE5KSkrh48SL9+vXjm2++ITU1FcD4CNoop25ubvcchxC3kjsEUeXd/AVtYWFR6PNbP3Pra2tra779\n9lv+8Y9/kJ6eTl5eHtOnT8fLy4uePXuyZ88eRo4cWeTxCjvOTUuWLCEiIoIaNWrQtm1bBg8ejLW1\nNXGXrBYAAACgSURBVEePHqVbt26AVmn8xRdf4OXlxRtvvEGfPn2wtLTEx8eHVatWAdp84//+97/v\n8wwJoZFmp0Lcg8zMTPr27cvu3bvNFsPVq1fp37+/WWMQVYsUGQlxD+rVq0ffvn2JiIgwWwyrV69m\n2rRpZju+qHrkDkEIIQQgdwhCCCH+IglBCCEEIAlBCCHEXyQhCCGEACQhCCGE+IskBCGEEAD8P7U0\n9aVlLh5rAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Biot no for this thermocouple is 0.00278\n", + "Bi is <0.1 and hence the thermocouple could be considered as a lumped heat capacity system and the assumption taken is valid.\n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.5, Page number: 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "T1=293; #Temperature of air around thermocouple, K\n", + "T2=373; #Wall temperature, K\n", + "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", + "s=5.67*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", + "\n", + "#Calculations\n", + "x=solve((h*(x-T1)+s*(x**4-T2**4)),x);\t #Calculating Thermocouple Temperature, K\n", + "y=x[1]-273;\t\t\t\t #Thermocouple Temperature, C\n", + "\n", + "#Results\n", + "print \"Thermocouple Temperature is :\",round(y,3),\"C\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thermocouple Temperature is : 28.395 C\n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.6, Page number: 34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "e=0.4; #emissivity\n", + "T1=293; #Temperature of air around Thermocouple, K\n", + "T2=273; #wall Temperature, K\n", + "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", + "s=5.6704*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", + "\n", + "#Calculations\n", + "z=solve(((s*e*((373)**4 - (x)**4)) - h*(x-293)),x);\t#Calculating Thermocouple Temperature, K\n", + "y=z[0]-273;\t\t\t\t\t #Thermocouple Temperature, C\n", + "\n", + "'''NOTE: Equation written is absolutely correct and solving this equation\n", + " should give real result as: 296.112 i.e. 23.112 C, but somehow python is giving wrong result.'''\n", + "\n", + "#Results\n", + "print \"Thermocouple Temperature is :\",round(y,1),\"C \\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thermocouple Temperature is : 25.9 C \n", + "\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter11-checkpoint.ipynb b/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter11-checkpoint.ipynb new file mode 100755 index 00000000..cec52317 --- /dev/null +++ b/A_Heat_Transfer_Text_Book/.ipynb_checkpoints/Chapter11-checkpoint.ipynb @@ -0,0 +1,631 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 11: An introduction to mass transfer" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.1, Page number:603" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "Mn2=0.7556; #mass fraction of nitrogen\n", + "Mo2=0.2315; #mass fraction of oxygen\n", + "Mar=0.01289; #mass fraction of argon gas\n", + "M1=28.02; #molar mass of N2,kg/kmol\n", + "M2=32; #molar mass of O2,kg/kmol\n", + "M3=39.95 ; #molar mass of Ar,kg/kmol\n", + "p=101325; #Atmospheric pressure in Pascal(Pa)\n", + "R=8314.5; #Gas constant, J/kmol-K\n", + "T=300; #Approximate room temperature, K\n", + "\n", + "#Calculations\n", + "Mair=(Mn2/M1+Mo2/M2+Mar/M3)**-1; #molar mass of air,kg/kmol\n", + "Xo2=Mo2*Mair/M2; #mole fraction of O2\n", + "PO2=Xo2*p; #partial pressure of O2,Pa\n", + "Co2=PO2/(R*T); #molar volume of O2,kmol/m**3\n", + "ao2=Co2*M2; #density of O2,kg/m**3\n", + "\n", + "\n", + "#Result\n", + "print \"Mole fraction of O2 is :\",round(Xo2,4),\"\\n\"\n", + "print \"Partial pressure of O2 is :\",round(PO2,4),\"\\n\"\n", + "print \"Molar volume of O2 is :\",round(Co2,4),\" kmol/m^3\\n\"\n", + "print \"Density of O2 is :\",round(ao2,4),\" kg/m^3\\n\"\n", + " #end" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mole fraction of O2 is : 0.2095 \n", + "\n", + "Partial pressure of O2 is : 21232.5938 \n", + "\n", + "Molar volume of O2 is : 0.0085 kmol/m^3\n", + "\n", + "Density of O2 is : 0.2724 kg/m^3\n", + "\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.2, Page number: 606" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "r=0.00241; #rate of consumption of carbon,kg/(m**2*s)\n", + "Mo2=0.2; #concentration of oxygen at surface s\n", + "Mco2=0.052; #concentration of CO2 at surface s\n", + "sd=0.29; #density of surface s,kg/m**3\n", + "\n", + "#since carbon flows through a second imaginary surface u, the mass fluxes are relatedd by Ncu=-12/32*No2s=12/44*Nco2s\n", + "#the minus sign arises because the O2 flow is opposite the C and CO2 flows.in steady state if we apply mass conservation to the control volume between the u and s surface, wee find that the total mass flux entering the u surface equals that leaving the s surface\n", + "Ncu=r; #mass fluxes of carbon in u surface,kg/m**2/s\n", + "\n", + "#Calculations\n", + "No2s=-32/12*Ncu; #mass flux of O2 in surface s,kg/(m**2*s)\n", + "Nco2s=44/12*Ncu; #mass flux of CO2 in surface s,kg/(m**2*s)\n", + "Vo2s=No2s/(Mo2*sd); #mass average speed,m/s\n", + "Vco2s=Nco2s/(sd); #mass average speed,m/s\n", + "Vs=(Nco2s+No2s)/sd; #effective mass average speed,m/s\n", + "j1=sd*Mo2*(Vo2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", + "j2=sd*Mco2*(Vco2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", + "#the diffusional mass fluxes are very nearly equal to the species m ss fluxes. tha is because the mass average speed is much less than species speeds.\n", + "\n", + "N1 = Ncu/12; #mole flux of carbon through the surface s,kmol/(m**2*s)\n", + "N2 = -N1; #mole flux of oxygen through the surface s,kmol/(m**2*s)\n", + "\n", + "#Result\n", + "print \"Mass flux of O2 through an imaginary surface is :\",round(j1,5),\"kg/(m^2*s)\\n\"\n", + "print \"Mass flux of CO2 through an imaginary surface is :\",round(j2,5),\"kg/(m^2*s)\\n\"\n", + "\n", + "print \"Mole flux of Co2 through an imaginary surface is :\",round(N1,5),\"kmol/(m^2*s)\\n\"\n", + "print \"Mole flux of O2through an imaginary surface is :\",round(N2,5),\"kmol/(m^2*s)\\n\"\n", + "print \"The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mass flux of O2 through an imaginary surface is : -0.00691 kg/(m^2*s)\n", + "\n", + "Mass flux of CO2 through an imaginary surface is : 0.00033 kg/(m^2*s)\n", + "\n", + "Mole flux of Co2 through an imaginary surface is : 0.0002 kmol/(m^2*s)\n", + "\n", + "Mole flux of O2through an imaginary surface is : -0.0002 kmol/(m^2*s)\n", + "\n", + "The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.3, Page number: 617" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=276; #temp.of air,K\n", + "aa=3.711; #lennard jones constant or collision diameter,A\n", + "ab=2.827; #lennard jones constant or collision diameter,A\n", + "b1=78.6; #lennard jones constant,K\n", + "b2=59.7; #lennard jones constant,K\n", + "Ma=28.97; #Molecular mass of air, kg/kmol\n", + "Mh=2.016; #Molecular mass of hydrogen, kg/kmol\n", + "\n", + "#Calculations\n", + "a=(aa+ab)/2; #effective molecular diameter for collisions of hydrogen and air,m\n", + "b=math.sqrt(b1*b2); #effective potential well depth,K\n", + "c=T1/b; \n", + "\n", + "d=0.8822; #potential well function, from table 11.3\n", + "Dab=(1.8583*math.pow(10,-7))*math.pow(T1,1.5)/(math.pow(a,2)*d)*math.sqrt(1/Mh+1/Ma); #diffusion coefficient of hydrogen in air,m**2/s\n", + "\n", + "\n", + "#Result\n", + "print \"Diffusion coefficient of hydrogen in air is :\",round(Dab,6),\"m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\\n\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Diffusion coefficient of hydrogen in air is : 6.6e-05 m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.4, Page number: 625" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "\n", + "#Variables\n", + "T1=373.15; #temp.of tea,K\n", + "XN2=0.7808; #mole fraction of nitrogen\n", + "XO2=0.2095; #mole fraction of oxygen\n", + "Xar=0.0093; #mole fraction of\n", + "Cp=1006 #mixture diffusivity,j/(kg*K)\n", + "\n", + "#Calculations\n", + "a=array(([3.798, 3.467, 3.542])); #collisin diameter,m\n", + "b=array(([71.4, 106.7, 93.3])); #lennard jones constant,K\n", + "M=array(([28.02, 32, 39.95])); #molar masses,kg/kmol\n", + "c=array(([0.9599, 1.057, 1.021])); #potential well function\n", + "d=array(([1.8*10**-5, 2.059*10**-5, 2.281*10**-5])); #calculated viscosity,kg/(m*s)\n", + "e=array(([1.8*10**-5, 2.07*10**-5, 2.29*10**-5])); # theoritical viscosity,kg/(m*s)\n", + "f=array(([0.0260, 0.02615, 0.01787])); #theoritical thermal conducitvity,W/(m*K)\n", + "\n", + "u=2.6693*10**-6*(M*T1)**0.5/((a**2*c)); #viscosity,kg/(m*s)\n", + "k=0.083228/((a**2*c*(T1/M**0.5))) #thermal conductivity,W/(m*s)\n", + "umc = XN2*u.item(0)/0.9978+XO2*u.item(1)/1.008+Xar*u.item(2)/0.9435 ; #calculated mixture viscosity,kg/(m*s)\n", + "umc1=1.857*10**-5;\n", + "\n", + "umd=XN2*e.item(0)/0.9978+XO2*e.item(1)/1.008+e.item(2)*Xar/0.9435; #theoritical mixture viscosity,kg/(m*s)\n", + "kmc=XN2*k.item(0)/0.9978+XO2*k.item(1)/1.008+Xar*k.item(2)/0.9435; #calculated thermal conducitvity,W/(m*K)\n", + "kmc1=0.02623;\n", + "kmd=XN2*f.item(0)/0.9978+XO2*f.item(1)/1.008+Xar*f.item(2)/0.9435; #theoritical thermal conductivity, W/(m*K)\n", + "pr=umd*Cp/kmd; #prandtl no.\n", + "\n", + "#Result\n", + "print \"Theoritical mixture viscosity is :\",round(umc1,6),\"kg/(m*s)\\n\"\n", + "print \"Calculated mixture viscosity is :\",round(umd,6),\"kg/(m*s)\\n\"\n", + "print \"Theoritical thermal conducitvity is :\",round(kmc1,4),\" W/(m*K)\\n\"\n", + "print \"Calculated thermal conducitvity is :\",round(kmd,4),\"W/(m*K)\\n\" \n", + "print \"Prandtl no. is :\",round(pr,4),\"\\n\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Theoritical mixture viscosity is : 1.9e-05 kg/(m*s)\n", + "\n", + "Calculated mixture viscosity is : 1.9e-05 kg/(m*s)\n", + "\n", + "Theoritical thermal conducitvity is : 0.0262 W/(m*K)\n", + "\n", + "Calculated thermal conducitvity is : 0.026 W/(m*K)\n", + "\n", + "Prandtl no. is : 0.7214 \n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.5, Page number: 632" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "#Variables\n", + "Patm=101.325;\t\t\t#Atmospheric pressure in kPa.\n", + "Mh20=18.02;\t\t\t\t#Molecular mass of H20 in kg/kmol.\n", + "Mair=28.96;\t\t\t\t#Molecular mass of air in kg/kmol.\n", + "Psat =array(([0.6113, 1.2276, 2.3385, 4.2461, 7.3837, 12.35, 19.941, 31.188, 47.39, 70.139, 101.325]));\t\t#Saturated pressure of watrer in kPa \n", + "T=array(([0.01, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]));\t\t#Temperature of air in in degree C\n", + "#Calculations\n", + "xw=Psat/Patm;\t\t\t\t\n", + "\n", + "mw=(xw*Mh20)/(xw*Mh20+(1-xw)*Mair);\t\t#Mass fraction of water vapour.\n", + "#Result\n", + "plt.plot(T,mw);\n", + "plt.xlabel(\"Temperature(Degree C)\")\n", + "plt.ylabel(\"Mass fraction of water vapour\");\n", + "plt.show()\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEPCAYAAACp/QjLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+P/AXmxtq5o5AoYDsIrglipKGmIqlmeJ2FQnJ\n3ErrV997b4bZ1bzebql071UrLRfEyBtmSqaCuYCWqJB4U1QScMOdRbbh8/vjxAiyzDBw5swwr+fj\nMQ+YmTOf855Tnjef3UwIIUBERFSJudIBEBGR4WFyICKiapgciIioGiYH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YWb7/9Nnr37g0f\nH58ah4/WtXuVi4sLPv30U7i7u+P+/fuYM2cOrKys6iy3clmRkZF4+eWX0bdvX3Tq1En9XnBwMP77\n3//Cx8cHR48eRXh4OA4dOoTevXsjOTlZ3SH9eHmvvPIK3N3d4evrCy8vL8yZMwcqlQpdu3ZFWVkZ\nCgsL1Z85fPiweijrvHnzsHbtWjz77LMAgDVr1uCXX36Bt7c3PDw8sG7dOgDAe++9h3379sHLywux\nsbHo2rWr+q/7ynEEBgZiypQpGDhwIHr16oWJEyciPz8fbm5u+OCDDzBixAh4e3tjxIgRNSatDz74\nAJ06dYK7uzu8vLwQHByMJ554AgBw/fp1dOjQoVpNhZo+LtlNRiEzMxPBwcFIS0tTOhStREZGws3N\nrUqfR32VlJTAwsICFhYWSEpKwty5c5GSktKIUWq2fv16FBQU4I033tDreUl57HMgo2FM7d5z587F\njBkzGpQcrly5gokTJ6K8vBzNmjXDhg0bGjFC7cTExCAuLk7v5yXlseZARETVsM+BiIiqYXIgIqJq\nmByIiKgaJgciIqqGyYGIiKphciAiomr+P6Ksmp778+IaAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.6, Page number: 634" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=263.15; #temp.of ice,K\n", + "p=101.325; #Atmospheric pressure, KPa\n", + "Molw=18.02; #Molecular mass of water vapour, g/mol\n", + "Mola=28.96; #Molecular mass of air, g/mol\n", + "\n", + "#Calculations\n", + "Pv=math.exp(21.99-6141/(T1)); #vapor pressure,KPa\n", + "xw=Pv/p; #mole fraction of water\n", + "mw=xw*Molw/(xw*Molw+(1-xw)*Mola); #mass fraction\n", + "\n", + "#Result\n", + "print \"Mass fraction of watervapor above the surface of ice is :\",round(mw,5),\"\\n\"\n", + "#end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mass fraction of watervapor above the surface of ice is : 0.0016 \n", + "\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.10, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=303; # isothermal temp.,K\n", + "v=5; #air speed,m/s\n", + "l=0.05; #length of naphthalene model that is flat, m\n", + "Mnap=128.2; #molar mass of naphthalene,kg/kmol\n", + "nu=1.867*10**-5; #Dynamic viscocity, m^2/s\n", + "\n", + "#Calculations\n", + "D=0.86*(10**-5); #diffusion coefficient of naphthalene in air,m/s\n", + "\n", + "Pv=10**(11.45-3729.3/T1)*133.31; #vapor pressure of napthalene, Pa\n", + "xn=Pv/101325; #mole fraction of naphthalene\n", + "mn=xn*Mnap/(xn*Mnap+(1-xn)*28.96); #mass fraction of naphthalene\n", + "mnp=0; #mass fraction of naphthalene in free stream is 0\n", + "\n", + "Rel=v*l/nu; #reynolds no.\n", + "Sc=nu/D; #schimidt no.\n", + "Nul=0.664*math.sqrt(Rel)*(Sc**(1/3)); #mass transfer nusselt no.\n", + "Gmn=D*Nul*1.166/l; #gas phase mass transfer coefficient,kg/(m**2*s)\n", + "n=Gmn*(mn-mnp); #average mass flux,kg/(m**2*s)\n", + "n1=n*1000*3600;# average mass flux, g/m**2.h\n", + "\n", + "#Result\n", + "print \"Average rate of loss of naphthalene from a part of model is :\",round(n,7),\"kg/(m^2*s) or \",round(n1),\"g/(m^2*h)\\n\"\n", + "print \"Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\\n\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average rate of loss of naphthalene from a part of model is : 1.61e-05 kg/(m^2*s) or 58.0 g/(m^2*h)\n", + "\n", + "Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\n", + "\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.11, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=300; #temp. of helium-water tube,K\n", + "h=0.4; #height of vertical wall,m\n", + "m=0.087*10**-3; #flow rate of helium,kg/(m**2*s)\n", + "#this is a uniform flux natural convection problem.\n", + "Mhes=0.01; # assuming the value of mass fraction of helium at the wall to be 0.01\n", + "Mhef=Mhes/2; #film composition\n", + "af=1.141; #film density,kg/m**3\n", + "wd=1.107; #wall density,kg/m**3\n", + "Dha=7.119*10**-5; #diffusion coefficient,m**2/s\n", + "u=1.857*10**-5; #film viscosity at 300K,kg/(m*s)\n", + "aa=1.177; #air density,kg/m**3\n", + "g=9.8; #Gravity constant, m/s**2\n", + "#Calculations\n", + "Sc=(u/af)/Dha; #schimidt no.\n", + "Ra1=g*(aa-wd)*m*h**4/(u*af*Dha**2*Mhes); #Rayleigh no.\n", + "Nu=6/5*(Ra1*Sc/(4+9*math.sqrt(Sc)+10*Sc))**(1/5); #approximate nusselt no.\n", + "s=m*h/(af*Dha*Nu); #average concentration of helium at the wall\n", + "#thus we have obtained an average wall concentration 14 oercent higher than our initial guess of Mhes.we repeat this calclations with revised values of densities to obtain Mhes = 0.01142\n", + "\n", + "\n", + "#Result\n", + "print \"Average conentration of helium at the wall is \",round(s,5),\",since the result is within 0.5 percent of our second guess, a third iteration is not needed\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average conentration of helium at the wall is 0.01136 ,since the result is within 0.5 percent of our second guess, a third iteration is not needed\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.14, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=325; #temp. of helium-water tube,K\n", + "l=0.2; #length of tube,m\n", + "x=0.01; # mole fraction of water\n", + "R=8314.472; #gas constant,J/(kmol*K)\n", + "Mw=18.02;#Molecular mass of water, g/mol\n", + "#the vapor pressure of the liquid water is approximately the saturation pressure at the water temp.\n", + "\n", + "#Calculations\n", + "p=1.341*10000 ; #vapor pressure using steam table,Pa\n", + "x1=p/101325; #mole fraction of saturated water\n", + "c=101325/(R*T1); #mole concentration in tube,kmol/m**3\n", + "D12=1.067*math.pow(10,-4); #diffusivity ofwater with respect to helium,m**2/s \n", + "Nw=c*D12*math.log(1+(x-x1)/(x1-1))/l ; #molar evaporation rate,kmol/(m**2*s)\n", + "nw=Nw*Mw; # mass evaporation rate,kg/(m**2*s)\n", + "\n", + "#S=1+(x1-1)*math.exp(Nw*y/(c*D12)) conentration distribution of water-vapor\n", + "#Result\n", + "print \"Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\n", + "\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.15, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=1473; #suraface temp.of hot water,K\n", + "x=0.05; #mass fraction of water\n", + "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", + "A=0.04; #suraface area of pan,m**2\n", + "\n", + " #only water vapour passes through the liquid surface, since air is not strongly absorbed into water under normal conditions.\n", + "#Calculations\n", + "p=38.58*1000; #saturation pressure of water,kPa\n", + "Xwater=p/101325; #mole fraction of saturated water\n", + "Mwater=Xwater*18.02/(Xwater*18.02+(1-Xwater)*28.96); #mass fraction of saturated water\n", + "\n", + "B=(x-Mwater)/(Mwater-1); #mass transfer driving force\n", + "m=Gm*B*A; #evaporation rate,kg/s\n", + "\n", + "#Result\n", + "print \"Evaporation rate is:\",round(m,6),\" kg/s\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Evaporation rate is: 0.000213 kg/s\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.16, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=298; #temp.of air,K\n", + "T2=323.15; #film temp.,K\n", + "x=0.05; #mass fraction of water at 75 C\n", + "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", + "A=0.04; #suraface area of pan,m**2\n", + "l=0.2; #length of pan in flow direction,m\n", + "v=5; #air speed,m/s\n", + "m=(x+0.277)/2; #film composition of water at 50 C\n", + "Mf=26.34; #mixture molecular weight,kg/kmol\n", + "p=101325; #Atmospheric pressure, Pa\n", + "R=8314.5; #Gas constant, J/kmol-K\n", + "Uf=1.75*math.pow(10,-5); #film viscosity,kg/(m*s)\n", + "B=0.314; #mass transfer driving force\n", + "D=2.96*math.pow(10,-5); #diffusivity of water in air,m**2/s\n", + "df=0.993; #Density of ideal air, kg/m**#\n", + "\n", + "#Calculations\n", + "af=p*Mf/(R*T2); \t #film density from ideal gas law,kg/m**3\n", + "Vf=Uf/af; #kinematic viscosity,m**2/s\n", + "Rel=v*l/Vf; #reynolds no. comes out to be 56,800 so the flow is laminar.\n", + "Sc=Vf/D; #scimidt no.\n", + "Nu=0.664*math.sqrt(Rel)*math.pow(Sc,1/3); #nussselt no.\n", + "Gmw1=Nu*(D*df/l); #appropriate value of mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", + "Gmw=Gmw1*(math.log(1+B)/B); \t #mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", + "\n", + "#Results\n", + "print \"Mass transfer gas phase coeffficient of water in air is :\",round(Gmw,4),\"kg/(m^2*s)\\nIn this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.01955648559 133.069905487\n", + "Mass transfer gas phase coeffficient of water in air is : 0.017 kg/(m^2*s)\n", + "In this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\n" + ] + } + ], + "prompt_number": 28 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/A_Heat_Transfer_Text_Book/Chapter1.ipynb b/A_Heat_Transfer_Text_Book/Chapter1.ipynb index 9deb4499..dd1cacc1 100755 --- a/A_Heat_Transfer_Text_Book/Chapter1.ipynb +++ b/A_Heat_Transfer_Text_Book/Chapter1.ipynb @@ -1,332 +1,334 @@ -{ - "metadata": { - "name": "" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 1 - \"Introduction\"" - ] - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.1, Page number: 13" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "k=35; #Thermal Conductivity, [W/m*K]\n", - "T1=110 # Temperature of front[C]\n", - "T2=50; # Temperature of back,[C]\n", - "A=0.4 #area of slab,[m**2]\n", - "x=0.03; #Thickness of slab,[m]\n", - "\n", - "#Calculations\n", - "q=-k*(T2-T1)/(1000*x); #formula for heat flux[KW/m^2]\n", - "Q=q*A; #formula for heat transfer rate[KW]\n", - "\n", - "#Results\n", - "print \"Heat flux is:\",q,\"KW/m^2\\n\"\n", - "print \"Heat transfer rate is:\",Q,\"KW \\n\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Heat flux is: 70.0 KW/m^2\n", - "\n", - "Heat transfer rate is: 28.0 KW \n", - "\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.2, Page number: 16" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from sympy import solve,symbols\n", - "\n", - "#Variables\n", - "x=symbols('x');\n", - "k1=372; # Thermal Conductivity of slab,W/m*K\n", - "x1=0.003; # Thickness of slab,m\n", - "x2=0.002 # Thickness of steel,m\n", - "k2=17; # Thermal Conductivity of steel,W/m*K\n", - "T1=400; # Temperature on one side,C\n", - "T2=100 #Temperature on other side,C\n", - "\n", - "#Calculations\n", - "Tcu=solve(x+2*x*(k1/x1)*(x2/k2)-(T1-T2),x);\n", - "#q=k1*(Tcu/x1)=k2*(Tss/x2);\n", - "Tss = Tcu[0]*(k1/x1)*(x2/k2); # formula for temperature gradient in steel side\n", - "Tcul=T1-Tss;\n", - "Tcur=T2+Tss;\n", - "q=k2*Tss/(1000*x2); # formula for heat conducted, kW\\m^2\n", - "\n", - "#Results\n", - "print \"Temperature on left copper side is :\",round(Tcul,3),\"C\\n\"\n", - "print \"Temperature on right copper side is :\",round(Tcur,3),\"C\\n\"\n", - "print \"Heat conducted through the wall is :\",round(q,3),\"kW\\m^2\\n\"\n", - "print \"Our initial approximation was accurate within a few percent.\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Temperature on left copper side is : 254.971 C\n", - "\n", - "Temperature on right copper side is : 245.029 C\n", - "\n", - "Heat conducted through the wall is : 1232.749 kW\\m^2\n", - "\n", - "Our initial approximation was accurate within a few percent.\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.3, Page number: 22" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "q1=6000; #Heat flux, W*m**-2\n", - "T1=120; #Heater Temperature, C\n", - "T2=70; #final Temperature of Heater, C\n", - "q2=2000; #final heat flux, W*m**-2\n", - "\n", - "#Calculations\n", - "h=q1/(T1-T2) #formula for average heat transfer cofficient\n", - "Tnew=T2+q2/h; #formula for new Heater temperature, C\n", - "\n", - "#Results\n", - "print \"Average Heat transfer coefficient is:\",h,\"W/(m^2*K)\\n\"\n", - "print \"New Heater Temperature is:\",round(Tnew,3),\"C\\n\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Average Heat transfer coefficient is: 120.0 W/(m^2*K)\n", - "\n", - "New Heater Temperature is: 86.667 C\n", - "\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.4, Page number: 25" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from numpy import array\n", - "from numpy import linspace\n", - "import matplotlib.pyplot as plt\n", - "from pylab import *\n", - "%matplotlib inline\n", - "\n", - "#Variables\n", - "h=250; #Heat Transfer Coefficient, W/(m**2*K)\n", - "k=45; #Thermal Conductivity, W/(m*K)\n", - "c=180; #Heat Capacity, J/(kg*K)\n", - "a=9300; #density, kg/m**3\n", - "T1=200; #temperature, C\n", - "D=0.001; #diameter of bead, m\n", - "t1=linspace(0,5,50); #defining time interval of 0.1 seconds\n", - "T=linspace(0,5,50);\n", - "i=0;\n", - "\n", - "#Calculations\n", - "while i<50:\n", - " T[i]=T1-c*math.exp(-t1[i]/((a*c*D)/(6*h))); #Calculating temperature at each time in degree C\n", - " i=i+1;\n", - "\n", - "plt.plot(t1,T);\n", - "plt.xlabel(\"Time(in sec)\");\n", - "plt.ylabel(\"Temperature(in degree C)\");\n", - "plt.title(\"Thermocouple response to a hot gas flow\");\n", - "plt.show();\n", - "\n", - "Bi = h*(D/2)/k; #biot no.\n", - "\n", - "#Results\n", - "print \"The value of Biot no for this thermocouple is\",round(Bi,5);\n", - "print \"Bi is <0.1 and hence the thermocouple could be considered as a lumped heat capacity system and the assumption taken is valid.\\n\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "ImportError", - "evalue": "DLL load failed: %1 is not a valid Win32 application.", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0m__future__\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdivision\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmath\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mlinspace\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 151\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mloader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mpackages\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 152\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 153\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0madd_newdocs\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 154\u001b[0m \u001b[0m__all__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'add_newdocs'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'ModuleDeprecationWarning'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 155\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\add_newdocs.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0m__future__\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdivision\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mabsolute_import\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mprint_function\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlib\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0madd_newdoc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;31m###############################################################################\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\lib\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mversion\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mversion\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m__version__\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mtype_check\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mindex_tricks\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mfunction_base\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\lib\\type_check.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 9\u001b[0m 'common_type']\n\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnumeric\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m_nx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 12\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnumeric\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0masarray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0masanyarray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0misnan\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[0mobj2sctype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mzeros\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\core\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mversion\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mversion\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m__version__\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmultiarray\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mumath\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0m_internal\u001b[0m \u001b[1;31m# for freeze programs\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mImportError\u001b[0m: DLL load failed: %1 is not a valid Win32 application." - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.5, Page number: 32" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from sympy import solve,symbols\n", - "\n", - "#Variables\n", - "x=symbols('x');\n", - "T1=293; #Temperature of air around thermocouple, K\n", - "T2=373; #Wall temperature, K\n", - "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", - "s=5.67*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", - "\n", - "#Calculations\n", - "x=solve((h*(x-T1)+s*(x**4-T2**4)),x);\t #Calculating Thermocouple Temperature, K\n", - "y=x[1]-273;\t\t\t\t #Thermocouple Temperature, C\n", - "\n", - "#Results\n", - "print \"Thermocouple Temperature is :\",round(y,3),\"C\\n\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Thermocouple Temperature is : 28.395 C\n", - "\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 1.6, Page number: 34" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from sympy import solve,symbols\n", - "\n", - "#Variables\n", - "x=symbols('x');\n", - "e=0.4; #emissivity\n", - "T1=293; #Temperature of air around Thermocouple, K\n", - "T2=273; #wall Temperature, K\n", - "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", - "s=5.6704*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", - "\n", - "#Calculations\n", - "z=solve(((s*e*((373)**4 - (x)**4)) - h*(x-293)),x);\t#Calculating Thermocouple Temperature, K\n", - "y=z[0]-273;\t\t\t\t\t #Thermocouple Temperature, C\n", - "\n", - "'''NOTE: Equation written is absolutely correct and solving this equation\n", - " should give real result as: 296.112 i.e. 23.112 C, but somehow python is giving wrong result.'''\n", - "\n", - "#Results\n", - "print \"Thermocouple Temperature is :\",round(y,1),\"C \\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Thermocouple Temperature is : 25.9 C \n", - "\n" - ] - } - ], - "prompt_number": 3 - } - ], - "metadata": {} - } - ] +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1 - \"Introduction\"" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.1, Page number: 13" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "k=35; #Thermal Conductivity, [W/m*K]\n", + "T1=110 # Temperature of front[C]\n", + "T2=50; # Temperature of back,[C]\n", + "A=0.4 #area of slab,[m**2]\n", + "x=0.03; #Thickness of slab,[m]\n", + "\n", + "#Calculations\n", + "q=-k*(T2-T1)/(1000*x); #formula for heat flux[KW/m^2]\n", + "Q=q*A; #formula for heat transfer rate[KW]\n", + "\n", + "#Results\n", + "print \"Heat flux is:\",q,\"KW/m^2\\n\"\n", + "print \"Heat transfer rate is:\",Q,\"KW \\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Heat flux is: 70.0 KW/m^2\n", + "\n", + "Heat transfer rate is: 28.0 KW \n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.2, Page number: 16" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "k1=372; # Thermal Conductivity of slab,W/m*K\n", + "x1=0.003; # Thickness of slab,m\n", + "x2=0.002 # Thickness of steel,m\n", + "k2=17; # Thermal Conductivity of steel,W/m*K\n", + "T1=400; # Temperature on one side,C\n", + "T2=100 #Temperature on other side,C\n", + "\n", + "#Calculations\n", + "Tcu=solve(x+2*x*(k1/x1)*(x2/k2)-(T1-T2),x);\n", + "#q=k1*(Tcu/x1)=k2*(Tss/x2);\n", + "Tss = Tcu[0]*(k1/x1)*(x2/k2); # formula for temperature gradient in steel side\n", + "Tcul=T1-Tss;\n", + "Tcur=T2+Tss;\n", + "q=k2*Tss/(1000*x2); # formula for heat conducted, kW\\m^2\n", + "\n", + "#Results\n", + "print \"Temperature on left copper side is :\",round(Tcul,3),\"C\\n\"\n", + "print \"Temperature on right copper side is :\",round(Tcur,3),\"C\\n\"\n", + "print \"Heat conducted through the wall is :\",round(q,3),\"kW\\m^2\\n\"\n", + "print \"Our initial approximation was accurate within a few percent.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature on left copper side is : 254.971 C\n", + "\n", + "Temperature on right copper side is : 245.029 C\n", + "\n", + "Heat conducted through the wall is : 1232.749 kW\\m^2\n", + "\n", + "Our initial approximation was accurate within a few percent.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.3, Page number: 22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "q1=6000; #Heat flux, W*m**-2\n", + "T1=120; #Heater Temperature, C\n", + "T2=70; #final Temperature of Heater, C\n", + "q2=2000; #final heat flux, W*m**-2\n", + "\n", + "#Calculations\n", + "h=q1/(T1-T2) #formula for average heat transfer cofficient\n", + "Tnew=T2+q2/h; #formula for new Heater temperature, C\n", + "\n", + "#Results\n", + "print \"Average Heat transfer coefficient is:\",h,\"W/(m^2*K)\\n\"\n", + "print \"New Heater Temperature is:\",round(Tnew,3),\"C\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average Heat transfer coefficient is: 120.0 W/(m^2*K)\n", + "\n", + "New Heater Temperature is: 86.667 C\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.4, Page number: 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "from numpy import linspace\n", + "import matplotlib.pyplot as plt\n", + "from pylab import *\n", + "%matplotlib inline\n", + "\n", + "#Variables\n", + "h=250; #Heat Transfer Coefficient, W/(m**2*K)\n", + "k=45; #Thermal Conductivity, W/(m*K)\n", + "c=180; #Heat Capacity, J/(kg*K)\n", + "a=9300; #density, kg/m**3\n", + "T1=200; #temperature, C\n", + "D=0.001; #diameter of bead, m\n", + "t1=linspace(0,5,50); #defining time interval of 0.1 seconds\n", + "T=linspace(0,5,50);\n", + "i=0;\n", + "\n", + "#Calculations\n", + "while i<50:\n", + " T[i]=T1-c*math.exp(-t1[i]/((a*c*D)/(6*h))); #Calculating temperature at each time in degree C\n", + " i=i+1;\n", + "\n", + "plt.plot(t1,T);\n", + "plt.xlabel(\"Time(in sec)\");\n", + "plt.ylabel(\"Temperature(in degree C)\");\n", + "plt.title(\"Thermocouple response to a hot gas flow\");\n", + "plt.show();\n", + "\n", + "Bi = h*(D/2)/k; #biot no.\n", + "\n", + "#Results\n", + "print \"The value of Biot no for this thermocouple is\",round(Bi,5);\n", + "print \"Bi is <0.1 and hence the thermocouple could be considered as a lumped heat capacity system and the assumption taken is valid.\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEZCAYAAACXRVJOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X1cjff/wPFXKgwphZNKMkVyM4Xcc9wUNsyYyEZjbPvZ\nfM2278zu3G30ta/5MmzfbYzZd9Nu1WxrmIoxcjs3ITeVlNyllKI6fX5/XHMmusOp0837+Xhcj3PO\ndc51Xe9zyfU+1+fWQimlEEIIUe3VMHcAQgghKgZJCEIIIQBJCEIIIf4iCUEIIQQgCUEIIcRfJCEI\nIYQAJCGYxezZsxk3bpy5w6gw9Ho9K1euNHcY4i+RkZE0bdrU3GGY3IQJE7C3t6dr165ERUVVye94\nvyQhlIF69ephY2ODjY0NNWrUoE6dOsbXX375JRYWFuYOsUKxsLCQc1KCyvIjYvXq1fTq1cvcYdxh\n27ZtbN68meTkZHbu3Il0vyqcJIQykJmZSUZGBhkZGTRr1owNGzYYX48dO9akf4wGg8Fk+6rs8vLy\nzB2CqKASEhJwc3Ojdu3a5g6lQpOEYAYWFhbk5OQQFBRE/fr1adu2LXv37jW+n5yczMiRI2ncuDEP\nPvggH3zwgfG92bNn8/jjjzNu3DhsbW1ZvXo1er2eN998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SURBVEePHqVbt26AVmn8xRdf4OXlxRtvvEGfPn2wtLTEx8eHVatWAdp84//+97/v\n8wwJoZFmp0Lcg8zMTPr27cvu3bvNFsPVq1fp37+/WWMQVYsUGQlxD+rVq0ffvn2JiIgwWwyrV69m\n2rRpZju+qHrkDkEIIQQgdwhCCCH+IglBCCEEIAlBCCHEXyQhCCGEACQhCCGE+IskBCGEEAD8P7U0\n9aVlLh5rAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The value of Biot no for this thermocouple is 0.00278\n", + "Bi is <0.1 and hence the thermocouple could be considered as a lumped heat capacity system and the assumption taken is valid.\n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.5, Page number: 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "T1=293; #Temperature of air around thermocouple, K\n", + "T2=373; #Wall temperature, K\n", + "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", + "s=5.67*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", + "\n", + "#Calculations\n", + "x=solve((h*(x-T1)+s*(x**4-T2**4)),x);\t #Calculating Thermocouple Temperature, K\n", + "y=x[1]-273;\t\t\t\t #Thermocouple Temperature, C\n", + "\n", + "#Results\n", + "print \"Thermocouple Temperature is :\",round(y,3),\"C\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thermocouple Temperature is : 28.395 C\n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 1.6, Page number: 34" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from sympy import solve,symbols\n", + "\n", + "#Variables\n", + "x=symbols('x');\n", + "e=0.4; #emissivity\n", + "T1=293; #Temperature of air around Thermocouple, K\n", + "T2=273; #wall Temperature, K\n", + "h=75; #Average Heat Transfer Coefficient, W/(m**2*K)\n", + "s=5.6704*10**-8; #stefan Boltzman constant, W/(m**2*K**4)\n", + "\n", + "#Calculations\n", + "z=solve(((s*e*((373)**4 - (x)**4)) - h*(x-293)),x);\t#Calculating Thermocouple Temperature, K\n", + "y=z[0]-273;\t\t\t\t\t #Thermocouple Temperature, C\n", + "\n", + "'''NOTE: Equation written is absolutely correct and solving this equation\n", + " should give real result as: 296.112 i.e. 23.112 C, but somehow python is giving wrong result.'''\n", + "\n", + "#Results\n", + "print \"Thermocouple Temperature is :\",round(y,1),\"C \\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thermocouple Temperature is : 25.9 C \n", + "\n" + ] + } + ], + "prompt_number": 3 + } + ], + "metadata": {} + } + ] } \ No newline at end of file diff --git a/A_Heat_Transfer_Text_Book/Chapter11.ipynb b/A_Heat_Transfer_Text_Book/Chapter11.ipynb index 9cd5d92a..cec52317 100755 --- a/A_Heat_Transfer_Text_Book/Chapter11.ipynb +++ b/A_Heat_Transfer_Text_Book/Chapter11.ipynb @@ -1,637 +1,631 @@ -{ - "metadata": { - "name": "" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 11: An introduction to mass transfer" - ] - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.1, Page number:603" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "\n", - "#Variables\n", - "Mn2=0.7556; #mass fraction of nitrogen\n", - "Mo2=0.2315; #mass fraction of oxygen\n", - "Mar=0.01289; #mass fraction of argon gas\n", - "M1=28.02; #molar mass of N2,kg/kmol\n", - "M2=32; #molar mass of O2,kg/kmol\n", - "M3=39.95 ; #molar mass of Ar,kg/kmol\n", - "p=101325; #Atmospheric pressure in Pascal(Pa)\n", - "R=8314.5; #Gas constant, J/kmol-K\n", - "T=300; #Approximate room temperature, K\n", - "\n", - "#Calculations\n", - "Mair=(Mn2/M1+Mo2/M2+Mar/M3)**-1; #molar mass of air,kg/kmol\n", - "Xo2=Mo2*Mair/M2; #mole fraction of O2\n", - "PO2=Xo2*p; #partial pressure of O2,Pa\n", - "Co2=PO2/(R*T); #molar volume of O2,kmol/m**3\n", - "ao2=Co2*M2; #density of O2,kg/m**3\n", - "\n", - "\n", - "#Result\n", - "print \"Mole fraction of O2 is :\",round(Xo2,4),\"\\n\"\n", - "print \"Partial pressure of O2 is :\",round(PO2,4),\"\\n\"\n", - "print \"Molar volume of O2 is :\",round(Co2,4),\" kmol/m^3\\n\"\n", - "print \"Density of O2 is :\",round(ao2,4),\" kg/m^3\\n\"\n", - " #end" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Mole fraction of O2 is : 0.2095 \n", - "\n", - "Partial pressure of O2 is : 21232.5938 \n", - "\n", - "Molar volume of O2 is : 0.0085 kmol/m^3\n", - "\n", - "Density of O2 is : 0.2724 kg/m^3\n", - "\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.2, Page number: 606" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "\n", - "#Variables\n", - "r=0.00241; #rate of consumption of carbon,kg/(m**2*s)\n", - "Mo2=0.2; #concentration of oxygen at surface s\n", - "Mco2=0.052; #concentration of CO2 at surface s\n", - "sd=0.29; #density of surface s,kg/m**3\n", - "\n", - "#since carbon flows through a second imaginary surface u, the mass fluxes are relatedd by Ncu=-12/32*No2s=12/44*Nco2s\n", - "#the minus sign arises because the O2 flow is opposite the C and CO2 flows.in steady state if we apply mass conservation to the control volume between the u and s surface, wee find that the total mass flux entering the u surface equals that leaving the s surface\n", - "Ncu=r; #mass fluxes of carbon in u surface,kg/m**2/s\n", - "\n", - "#Calculations\n", - "No2s=-32/12*Ncu; #mass flux of O2 in surface s,kg/(m**2*s)\n", - "Nco2s=44/12*Ncu; #mass flux of CO2 in surface s,kg/(m**2*s)\n", - "Vo2s=No2s/(Mo2*sd); #mass average speed,m/s\n", - "Vco2s=Nco2s/(sd); #mass average speed,m/s\n", - "Vs=(Nco2s+No2s)/sd; #effective mass average speed,m/s\n", - "j1=sd*Mo2*(Vo2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", - "j2=sd*Mco2*(Vco2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", - "#the diffusional mass fluxes are very nearly equal to the species m ss fluxes. tha is because the mass average speed is much less than species speeds.\n", - "\n", - "N1 = Ncu/12; #mole flux of carbon through the surface s,kmol/(m**2*s)\n", - "N2 = -N1; #mole flux of oxygen through the surface s,kmol/(m**2*s)\n", - "\n", - "#Result\n", - "print \"Mass flux of O2 through an imaginary surface is :\",round(j1,5),\"kg/(m^2*s)\\n\"\n", - "print \"Mass flux of CO2 through an imaginary surface is :\",round(j2,5),\"kg/(m^2*s)\\n\"\n", - "\n", - "print \"Mole flux of Co2 through an imaginary surface is :\",round(N1,5),\"kmol/(m^2*s)\\n\"\n", - "print \"Mole flux of O2through an imaginary surface is :\",round(N2,5),\"kmol/(m^2*s)\\n\"\n", - "print \"The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\"\n", - " #end\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Mass flux of O2 through an imaginary surface is : -0.00691 kg/(m^2*s)\n", - "\n", - "Mass flux of CO2 through an imaginary surface is : 0.00033 kg/(m^2*s)\n", - "\n", - "Mole flux of Co2 through an imaginary surface is : 0.0002 kmol/(m^2*s)\n", - "\n", - "Mole flux of O2through an imaginary surface is : -0.0002 kmol/(m^2*s)\n", - "\n", - "The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.3, Page number: 617" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "T1=276; #temp.of air,K\n", - "aa=3.711; #lennard jones constant or collision diameter,A\n", - "ab=2.827; #lennard jones constant or collision diameter,A\n", - "b1=78.6; #lennard jones constant,K\n", - "b2=59.7; #lennard jones constant,K\n", - "Ma=28.97; #Molecular mass of air, kg/kmol\n", - "Mh=2.016; #Molecular mass of hydrogen, kg/kmol\n", - "\n", - "#Calculations\n", - "a=(aa+ab)/2; #effective molecular diameter for collisions of hydrogen and air,m\n", - "b=math.sqrt(b1*b2); #effective potential well depth,K\n", - "c=T1/b; \n", - "\n", - "d=0.8822; #potential well function, from table 11.3\n", - "Dab=(1.8583*math.pow(10,-7))*math.pow(T1,1.5)/(math.pow(a,2)*d)*math.sqrt(1/Mh+1/Ma); #diffusion coefficient of hydrogen in air,m**2/s\n", - "\n", - "\n", - "#Result\n", - "print \"Diffusion coefficient of hydrogen in air is :\",round(Dab,6),\"m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\\n\"\n", - " #end\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Diffusion coefficient of hydrogen in air is : 6.6e-05 m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\n", - "\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.4, Page number: 625" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from numpy import array\n", - "\n", - "#Variables\n", - "T1=373.15; #temp.of tea,K\n", - "XN2=0.7808; #mole fraction of nitrogen\n", - "XO2=0.2095; #mole fraction of oxygen\n", - "Xar=0.0093; #mole fraction of\n", - "Cp=1006 #mixture diffusivity,j/(kg*K)\n", - "\n", - "#Calculations\n", - "a=array(([3.798, 3.467, 3.542])); #collisin diameter,m\n", - "b=array(([71.4, 106.7, 93.3])); #lennard jones constant,K\n", - "M=array(([28.02, 32, 39.95])); #molar masses,kg/kmol\n", - "c=array(([0.9599, 1.057, 1.021])); #potential well function\n", - "d=array(([1.8*10**-5, 2.059*10**-5, 2.281*10**-5])); #calculated viscosity,kg/(m*s)\n", - "e=array(([1.8*10**-5, 2.07*10**-5, 2.29*10**-5])); # theoritical viscosity,kg/(m*s)\n", - "f=array(([0.0260, 0.02615, 0.01787])); #theoritical thermal conducitvity,W/(m*K)\n", - "\n", - "u=2.6693*10**-6*(M*T1)**0.5/((a**2*c)); #viscosity,kg/(m*s)\n", - "k=0.083228/((a**2*c*(T1/M**0.5))) #thermal conductivity,W/(m*s)\n", - "umc = XN2*u.item(0)/0.9978+XO2*u.item(1)/1.008+Xar*u.item(2)/0.9435 ; #calculated mixture viscosity,kg/(m*s)\n", - "umc1=1.857*10**-5;\n", - "\n", - "umd=XN2*e.item(0)/0.9978+XO2*e.item(1)/1.008+e.item(2)*Xar/0.9435; #theoritical mixture viscosity,kg/(m*s)\n", - "kmc=XN2*k.item(0)/0.9978+XO2*k.item(1)/1.008+Xar*k.item(2)/0.9435; #calculated thermal conducitvity,W/(m*K)\n", - "kmc1=0.02623;\n", - "kmd=XN2*f.item(0)/0.9978+XO2*f.item(1)/1.008+Xar*f.item(2)/0.9435; #theoritical thermal conductivity, W/(m*K)\n", - "pr=umd*Cp/kmd; #prandtl no.\n", - "\n", - "#Result\n", - "print \"Theoritical mixture viscosity is :\",round(umc1,6),\"kg/(m*s)\\n\"\n", - "print \"Calculated mixture viscosity is :\",round(umd,6),\"kg/(m*s)\\n\"\n", - "print \"Theoritical thermal conducitvity is :\",round(kmc1,4),\" W/(m*K)\\n\"\n", - "print \"Calculated thermal conducitvity is :\",round(kmd,4),\"W/(m*K)\\n\" \n", - "print \"Prandtl no. is :\",round(pr,4),\"\\n\"\n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "ImportError", - "evalue": "DLL load failed: %1 is not a valid Win32 application.", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0m__future__\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdivision\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmath\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;31m#Question\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;34m'''Compute the transport properties of normal air at 300 K.'''\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 151\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mloader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mpackages\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 152\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 153\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0madd_newdocs\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 154\u001b[0m \u001b[0m__all__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'add_newdocs'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'ModuleDeprecationWarning'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 155\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\add_newdocs.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0m__future__\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mdivision\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mabsolute_import\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mprint_function\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlib\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0madd_newdoc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;31m###############################################################################\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\lib\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mversion\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mversion\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m__version__\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mtype_check\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mindex_tricks\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m\u001b[0mfunction_base\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\lib\\type_check.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 9\u001b[0m 'common_type']\n\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnumeric\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m_nx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 12\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnumeric\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0masarray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0masanyarray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0misnan\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[0mobj2sctype\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mzeros\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32mC:\\Users\\jaidev\\Anaconda\\lib\\site-packages\\numpy\\core\\__init__.py\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mnumpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mversion\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mversion\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0m__version__\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmultiarray\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mumath\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;33m.\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0m_internal\u001b[0m \u001b[1;31m# for freeze programs\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mImportError\u001b[0m: DLL load failed: %1 is not a valid Win32 application." - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.5, Page number: 632" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "from numpy import array\n", - "import matplotlib.pyplot as plt\n", - "%matplotlib inline\n", - "\n", - "#Variables\n", - "Patm=101.325;\t\t\t#Atmospheric pressure in kPa.\n", - "Mh20=18.02;\t\t\t\t#Molecular mass of H20 in kg/kmol.\n", - "Mair=28.96;\t\t\t\t#Molecular mass of air in kg/kmol.\n", - "Psat =array(([0.6113, 1.2276, 2.3385, 4.2461, 7.3837, 12.35, 19.941, 31.188, 47.39, 70.139, 101.325]));\t\t#Saturated pressure of watrer in kPa \n", - "T=array(([0.01, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]));\t\t#Temperature of air in in degree C\n", - "#Calculations\n", - "xw=Psat/Patm;\t\t\t\t\n", - "\n", - "mw=(xw*Mh20)/(xw*Mh20+(1-xw)*Mair);\t\t#Mass fraction of water vapour.\n", - "#Result\n", - "plt.plot(T,mw);\n", - "plt.xlabel(\"Temperature(Degree C)\")\n", - "plt.ylabel(\"Mass fraction of water vapour\");\n", - "plt.show()\n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Populating the interactive namespace from numpy and matplotlib\n" - ] - }, - { - "metadata": {}, - "output_type": "display_data", - "png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEPCAYAAACp/QjLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+P/AXmxtq5o5AoYDsIrglipKGmIqlmeJ2FQnJ\n3ErrV997b4bZ1bzebql071UrLRfEyBtmSqaCuYCWqJB4U1QScMOdRbbh8/vjxAiyzDBw5swwr+fj\nMQ+YmTOf855Tnjef3UwIIUBERFSJudIBEBGR4WFyICKiapgciIioGiYHIiKqhsmBiIiqYXIgIqJq\nZE0Os2bNQpcuXeDl5VXrMQsWLICzszO8vb1x6tQpOcMhIiItyZocQkNDER8fX+v7e/bsQUZGBi5c\nuID169djzpw5coZDRERakjU5+Pv748knn6z1/V27dmHGjBkAgAEDBuDevXu4ceOGnCEREZEWFO1z\nyMnJgb29vfq5nZ0dsrOzFYyIiIgAA+iQfnz1DjMzM4UiISKiCpZKntzW1hZZWVnq59nZ2bC1ta12\nnJOTEy5evKjP0IiIjJ6joyMyMjJ0+qyiNYexY8fiq6++AgAkJyejXbt26NKlS7XjLl68CCEEH0Lg\nvffeUzwGQ3nwWvBa8FrU/FixQmD2bNGgP6plrTlMnjwZhw4dwq1bt2Bvb4+lS5eitLQUABAREYFR\no0Zhz549cHJygrW1NTZu3ChnOERETZ4QwObNwLp1wPr1upcja3KIjo7WeExUVJScIRARmZQzZ4DC\nQsDPr2HlKN4hTfUTEBCgdAgGg9fiEV6LR0z9WmzZAkydCpg38O5uJoQw+M1+zMzMYARhEhEpSqUC\n7O2BAwcAN7eG3TtZcyAiaiISEoBu3aTE0FBMDkRETcTmzcC0aY1TFpuViIiagIICwNYW+N//gK5d\npdfYrEREZOJ27QKeeeZRYmgoJgcioiZgyxZg+vTGK4/NSkRERu7mTaBnTyAnB7C2fvQ6m5WIiExY\nTAwQHFw1MTQUkwMRkZHbsqXxRilVYHIg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a5tGYmgo1hyIiAC88460V8OOHUpH0nhkHa1E\nRNTUnTwJbNwI6HGEvsFjsxIRmbSSEmDWLOCjj4AuXZSOxnAwORCRSVu5ErCzA6ZOVToSw6JVn4NK\npcKNGzdQVlamfu2pp56SNbDK2OdARHI4exYICABSUqTF9ZoaWfsc1q5di6VLl6Jz586wsLBQv55m\nylMHicjoqVRSc9IHHzTNxNBQGmsOjo6OOHHiBDp06KCvmKphzYGIGttHHwG7d0vLZJg30QZ2WWsO\nTz31FNq2batT4UREhigjA1ixAjh+vOkmhobSmBy6d++OZ599FqNHj0azP7ZBMjMzw6JFi2QPjoio\nsZWXA6+8AvzlL4Cjo9LRGC6NOfOpp57Cc889h5KSEuTn5yMvLw95eXlaFR4fHw9XV1c4Oztj5cqV\ntR73888/w9LSEjt37tQ+ciIiHaxfDxQXS2soUe20niFdkRDaaLlMoUqlgouLC/bv3w9bW1v069cP\n0dHRcHNzq3ZcYGAgWrVqhdDQULz00kvVg2SfAxE1gqwswNcXOHQIcHdXOhr5ybq2UlpaGnx8fODh\n4QEPDw/06dMHv/76q8aCT5w4AScnJzg4OMDKygohISGIi4urdtzatWsxYcIEdOrUSacvQESkDSGA\niAhg4ULTSAwNpTE5zJ49G//85z9x5coVXLlyBR999BFmz56tseCcnBzYVxofZmdnh5ycnGrHxMXF\nYc6cOQCkLEdEJIctW4CrV4G331Y6EuOgsUO6sLAQzz77rPp5QEAACgoKNBaszY3+9ddfx4cffqiu\n+rDpiIjkcP068OabwN69gJWV0tEYB61GKy1btgzTp0+HEAJbt25Fjx49NBZsa2uLrKws9fOsrCzY\n2dlVOebkyZMICQkBANy6dQt79+6FlZUVxo4dW628yMhI9e8BAQEICAjQGAMREQDMmydNePP1VToS\neSUmJiIxMbFRytLYIX3nzh289957OHr0KADA398fkZGRePLJJ+ssuKysDC4uLjhw4AC6deuG/v37\n19ghXSE0NBTBwcEYP3589SDZIU1EOvrmG2nY6unTgJ43sVScrJPg2rdvj7Vr19a/YEtLREVFISgo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qsc2YMQPLly+vNQ4nJydcuXIFeXl51fYLqRyDqe6JYMrY50B6\n0bx5c+Tm5iI5ORmANEImPT29XmVcuXJF/flt27bB398fLi4udZZb+eb64MEDda1i06ZN6tfbtGlT\nZUSOg4MDTp48CQDYtWsXSktLa4wnKCgI//rXv9TJ6/z58ygsLMTTTz+t7veoSWpqKj744APMnTsX\nADBixAisWbNG/f6ZM2cAAIMGDcKOHTsASLWDu3fv1hrHF198gYKCAgDSLoq5ubkYPnw4YmNjkZub\nC0DafP7KlStVPtuqVSuEhYVh4cKF6u+Zm5urrg0B0u5ipraXCjE5kJ5YWFggNjYWb7/9Nnr37g0f\nH58ah4/WtXuVi4sLPv30U7i7u+P+/fuYM2cOrKys6iy3clmRkZF4+eWX0bdvX3Tq1En9XnBwMP77\n3//Cx8cHR48eRXh4OA4dOoTevXsjOTlZ3SH9eHmvvPIK3N3d4evrCy8vL8yZMwcqlQpdu3ZFWVkZ\nCgsL1Z85fPiweijrvHnzsHbtWjz77LMAgDVr1uCXX36Bt7c3PDw8sG7dOgDAe++9h3379sHLywux\nsbHo2rWr+q/7ynEEBgZiypQpGDhwIHr16oWJEyciPz8fbm5u+OCDDzBixAh4e3tjxIgRNSatDz74\nAJ06dYK7uzu8vLwQHByMJ554AgBw/fp1dOjQoVpNhZo+LtlNRiEzMxPBwcFIS0tTOhStREZGws3N\nrUqfR32VlJTAwsICFhYWSEpKwty5c5GSktKIUWq2fv16FBQU4I033tDreUl57HMgo2FM7d5z587F\njBkzGpQcrly5gokTJ6K8vBzNmjXDhg0bGjFC7cTExCAuLk7v5yXlseZARETVsM+BiIiqYXIgIqJq\nmByIiKgaJgciIqqGyYGIiKphciAiomr+P6Ksmp778+IaAAAAAElFTkSuQmCC\n", - "text": [ - "" - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.6, Page number: 634" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "T1=263.15; #temp.of ice,K\n", - "p=101.325; #Atmospheric pressure, KPa\n", - "Molw=18.02; #Molecular mass of water vapour, g/mol\n", - "Mola=28.96; #Molecular mass of air, g/mol\n", - "\n", - "#Calculations\n", - "Pv=math.exp(21.99-6141/(T1)); #vapor pressure,KPa\n", - "xw=Pv/p; #mole fraction of water\n", - "mw=xw*Molw/(xw*Molw+(1-xw)*Mola); #mass fraction\n", - "\n", - "#Result\n", - "print \"Mass fraction of watervapor above the surface of ice is :\",round(mw,5),\"\\n\"\n", - "#end\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Mass fraction of watervapor above the surface of ice is : 0.0016 \n", - "\n" - ] - } - ], - "prompt_number": 26 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.10, Page number:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "\n", - "#Variables\n", - "T1=303; # isothermal temp.,K\n", - "v=5; #air speed,m/s\n", - "l=0.05; #length of naphthalene model that is flat, m\n", - "Mnap=128.2; #molar mass of naphthalene,kg/kmol\n", - "nu=1.867*10**-5; #Dynamic viscocity, m^2/s\n", - "\n", - "#Calculations\n", - "D=0.86*(10**-5); #diffusion coefficient of naphthalene in air,m/s\n", - "\n", - "Pv=10**(11.45-3729.3/T1)*133.31; #vapor pressure of napthalene, Pa\n", - "xn=Pv/101325; #mole fraction of naphthalene\n", - "mn=xn*Mnap/(xn*Mnap+(1-xn)*28.96); #mass fraction of naphthalene\n", - "mnp=0; #mass fraction of naphthalene in free stream is 0\n", - "\n", - "Rel=v*l/nu; #reynolds no.\n", - "Sc=nu/D; #schimidt no.\n", - "Nul=0.664*math.sqrt(Rel)*(Sc**(1/3)); #mass transfer nusselt no.\n", - "Gmn=D*Nul*1.166/l; #gas phase mass transfer coefficient,kg/(m**2*s)\n", - "n=Gmn*(mn-mnp); #average mass flux,kg/(m**2*s)\n", - "n1=n*1000*3600;# average mass flux, g/m**2.h\n", - "\n", - "#Result\n", - "print \"Average rate of loss of naphthalene from a part of model is :\",round(n,7),\"kg/(m^2*s) or \",round(n1),\"g/(m^2*h)\\n\"\n", - "print \"Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\\n\"\n", - " #end\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Average rate of loss of naphthalene from a part of model is : 1.61e-05 kg/(m^2*s) or 58.0 g/(m^2*h)\n", - "\n", - "Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\n", - "\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.11, Page number:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "\n", - "#Variables\n", - "T1=300; #temp. of helium-water tube,K\n", - "h=0.4; #height of vertical wall,m\n", - "m=0.087*10**-3; #flow rate of helium,kg/(m**2*s)\n", - "#this is a uniform flux natural convection problem.\n", - "Mhes=0.01; # assuming the value of mass fraction of helium at the wall to be 0.01\n", - "Mhef=Mhes/2; #film composition\n", - "af=1.141; #film density,kg/m**3\n", - "wd=1.107; #wall density,kg/m**3\n", - "Dha=7.119*10**-5; #diffusion coefficient,m**2/s\n", - "u=1.857*10**-5; #film viscosity at 300K,kg/(m*s)\n", - "aa=1.177; #air density,kg/m**3\n", - "g=9.8; #Gravity constant, m/s**2\n", - "#Calculations\n", - "Sc=(u/af)/Dha; #schimidt no.\n", - "Ra1=g*(aa-wd)*m*h**4/(u*af*Dha**2*Mhes); #Rayleigh no.\n", - "Nu=6/5*(Ra1*Sc/(4+9*math.sqrt(Sc)+10*Sc))**(1/5); #approximate nusselt no.\n", - "s=m*h/(af*Dha*Nu); #average concentration of helium at the wall\n", - "#thus we have obtained an average wall concentration 14 oercent higher than our initial guess of Mhes.we repeat this calclations with revised values of densities to obtain Mhes = 0.01142\n", - "\n", - "\n", - "#Result\n", - "print \"Average conentration of helium at the wall is \",round(s,5),\",since the result is within 0.5 percent of our second guess, a third iteration is not needed\"\n", - " #end\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Average conentration of helium at the wall is 0.01136 ,since the result is within 0.5 percent of our second guess, a third iteration is not needed\n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.14, Page number:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "T1=325; #temp. of helium-water tube,K\n", - "l=0.2; #length of tube,m\n", - "x=0.01; # mole fraction of water\n", - "R=8314.472; #gas constant,J/(kmol*K)\n", - "Mw=18.02;#Molecular mass of water, g/mol\n", - "#the vapor pressure of the liquid water is approximately the saturation pressure at the water temp.\n", - "\n", - "#Calculations\n", - "p=1.341*10000 ; #vapor pressure using steam table,Pa\n", - "x1=p/101325; #mole fraction of saturated water\n", - "c=101325/(R*T1); #mole concentration in tube,kmol/m**3\n", - "D12=1.067*math.pow(10,-4); #diffusivity ofwater with respect to helium,m**2/s \n", - "Nw=c*D12*math.log(1+(x-x1)/(x1-1))/l ; #molar evaporation rate,kmol/(m**2*s)\n", - "nw=Nw*Mw; # mass evaporation rate,kg/(m**2*s)\n", - "\n", - "#S=1+(x1-1)*math.exp(Nw*y/(c*D12)) conentration distribution of water-vapor\n", - "#Result\n", - "print \"Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\n", - "\n" - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.15, Page number:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "\n", - "#Variables\n", - "T1=1473; #suraface temp.of hot water,K\n", - "x=0.05; #mass fraction of water\n", - "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", - "A=0.04; #suraface area of pan,m**2\n", - "\n", - " #only water vapour passes through the liquid surface, since air is not strongly absorbed into water under normal conditions.\n", - "#Calculations\n", - "p=38.58*1000; #saturation pressure of water,kPa\n", - "Xwater=p/101325; #mole fraction of saturated water\n", - "Mwater=Xwater*18.02/(Xwater*18.02+(1-Xwater)*28.96); #mass fraction of saturated water\n", - "\n", - "B=(x-Mwater)/(Mwater-1); #mass transfer driving force\n", - "m=Gm*B*A; #evaporation rate,kg/s\n", - "\n", - "#Result\n", - "print \"Evaporation rate is:\",round(m,6),\" kg/s\"\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Evaporation rate is: 0.000213 kg/s\n" - ] - } - ], - "prompt_number": 23 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": [ - "Example 11.16, Page number:" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "from __future__ import division\n", - "import math\n", - "\n", - "#Variables\n", - "T1=298; #temp.of air,K\n", - "T2=323.15; #film temp.,K\n", - "x=0.05; #mass fraction of water at 75 C\n", - "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", - "A=0.04; #suraface area of pan,m**2\n", - "l=0.2; #length of pan in flow direction,m\n", - "v=5; #air speed,m/s\n", - "m=(x+0.277)/2; #film composition of water at 50 C\n", - "Mf=26.34; #mixture molecular weight,kg/kmol\n", - "p=101325; #Atmospheric pressure, Pa\n", - "R=8314.5; #Gas constant, J/kmol-K\n", - "Uf=1.75*math.pow(10,-5); #film viscosity,kg/(m*s)\n", - "B=0.314; #mass transfer driving force\n", - "D=2.96*math.pow(10,-5); #diffusivity of water in air,m**2/s\n", - "df=0.993; #Density of ideal air, kg/m**#\n", - "\n", - "#Calculations\n", - "af=p*Mf/(R*T2); \t #film density from ideal gas law,kg/m**3\n", - "Vf=Uf/af; #kinematic viscosity,m**2/s\n", - "Rel=v*l/Vf; #reynolds no. comes out to be 56,800 so the flow is laminar.\n", - "Sc=Vf/D; #scimidt no.\n", - "Nu=0.664*math.sqrt(Rel)*math.pow(Sc,1/3); #nussselt no.\n", - "Gmw1=Nu*(D*df/l); #appropriate value of mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", - "Gmw=Gmw1*(math.log(1+B)/B); \t #mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", - "\n", - "#Results\n", - "print \"Mass transfer gas phase coeffficient of water in air is :\",round(Gmw,4),\"kg/(m^2*s)\\nIn this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.01955648559 133.069905487\n", - "Mass transfer gas phase coeffficient of water in air is : 0.017 kg/(m^2*s)\n", - "In this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\n" - ] - } - ], - "prompt_number": 28 - } - ], - "metadata": {} - } - ] +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 11: An introduction to mass transfer" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.1, Page number:603" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "Mn2=0.7556; #mass fraction of nitrogen\n", + "Mo2=0.2315; #mass fraction of oxygen\n", + "Mar=0.01289; #mass fraction of argon gas\n", + "M1=28.02; #molar mass of N2,kg/kmol\n", + "M2=32; #molar mass of O2,kg/kmol\n", + "M3=39.95 ; #molar mass of Ar,kg/kmol\n", + "p=101325; #Atmospheric pressure in Pascal(Pa)\n", + "R=8314.5; #Gas constant, J/kmol-K\n", + "T=300; #Approximate room temperature, K\n", + "\n", + "#Calculations\n", + "Mair=(Mn2/M1+Mo2/M2+Mar/M3)**-1; #molar mass of air,kg/kmol\n", + "Xo2=Mo2*Mair/M2; #mole fraction of O2\n", + "PO2=Xo2*p; #partial pressure of O2,Pa\n", + "Co2=PO2/(R*T); #molar volume of O2,kmol/m**3\n", + "ao2=Co2*M2; #density of O2,kg/m**3\n", + "\n", + "\n", + "#Result\n", + "print \"Mole fraction of O2 is :\",round(Xo2,4),\"\\n\"\n", + "print \"Partial pressure of O2 is :\",round(PO2,4),\"\\n\"\n", + "print \"Molar volume of O2 is :\",round(Co2,4),\" kmol/m^3\\n\"\n", + "print \"Density of O2 is :\",round(ao2,4),\" kg/m^3\\n\"\n", + " #end" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mole fraction of O2 is : 0.2095 \n", + "\n", + "Partial pressure of O2 is : 21232.5938 \n", + "\n", + "Molar volume of O2 is : 0.0085 kmol/m^3\n", + "\n", + "Density of O2 is : 0.2724 kg/m^3\n", + "\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.2, Page number: 606" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "r=0.00241; #rate of consumption of carbon,kg/(m**2*s)\n", + "Mo2=0.2; #concentration of oxygen at surface s\n", + "Mco2=0.052; #concentration of CO2 at surface s\n", + "sd=0.29; #density of surface s,kg/m**3\n", + "\n", + "#since carbon flows through a second imaginary surface u, the mass fluxes are relatedd by Ncu=-12/32*No2s=12/44*Nco2s\n", + "#the minus sign arises because the O2 flow is opposite the C and CO2 flows.in steady state if we apply mass conservation to the control volume between the u and s surface, wee find that the total mass flux entering the u surface equals that leaving the s surface\n", + "Ncu=r; #mass fluxes of carbon in u surface,kg/m**2/s\n", + "\n", + "#Calculations\n", + "No2s=-32/12*Ncu; #mass flux of O2 in surface s,kg/(m**2*s)\n", + "Nco2s=44/12*Ncu; #mass flux of CO2 in surface s,kg/(m**2*s)\n", + "Vo2s=No2s/(Mo2*sd); #mass average speed,m/s\n", + "Vco2s=Nco2s/(sd); #mass average speed,m/s\n", + "Vs=(Nco2s+No2s)/sd; #effective mass average speed,m/s\n", + "j1=sd*Mo2*(Vo2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", + "j2=sd*Mco2*(Vco2s-Vs); #diffusional mass flux,kg/(m**2*s)\n", + "#the diffusional mass fluxes are very nearly equal to the species m ss fluxes. tha is because the mass average speed is much less than species speeds.\n", + "\n", + "N1 = Ncu/12; #mole flux of carbon through the surface s,kmol/(m**2*s)\n", + "N2 = -N1; #mole flux of oxygen through the surface s,kmol/(m**2*s)\n", + "\n", + "#Result\n", + "print \"Mass flux of O2 through an imaginary surface is :\",round(j1,5),\"kg/(m^2*s)\\n\"\n", + "print \"Mass flux of CO2 through an imaginary surface is :\",round(j2,5),\"kg/(m^2*s)\\n\"\n", + "\n", + "print \"Mole flux of Co2 through an imaginary surface is :\",round(N1,5),\"kmol/(m^2*s)\\n\"\n", + "print \"Mole flux of O2through an imaginary surface is :\",round(N2,5),\"kmol/(m^2*s)\\n\"\n", + "print \"The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mass flux of O2 through an imaginary surface is : -0.00691 kg/(m^2*s)\n", + "\n", + "Mass flux of CO2 through an imaginary surface is : 0.00033 kg/(m^2*s)\n", + "\n", + "Mole flux of Co2 through an imaginary surface is : 0.0002 kmol/(m^2*s)\n", + "\n", + "Mole flux of O2through an imaginary surface is : -0.0002 kmol/(m^2*s)\n", + "\n", + "The two diffusional mole fluxes sum to zero themselves because ther is no convective mole flux for other species to diffuse against. the reader may find the velocity of the interface.that calculation shows the interface to be receding so slowly that the velocities are equal to those that would be seen by a stationary observer.\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.3, Page number: 617" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=276; #temp.of air,K\n", + "aa=3.711; #lennard jones constant or collision diameter,A\n", + "ab=2.827; #lennard jones constant or collision diameter,A\n", + "b1=78.6; #lennard jones constant,K\n", + "b2=59.7; #lennard jones constant,K\n", + "Ma=28.97; #Molecular mass of air, kg/kmol\n", + "Mh=2.016; #Molecular mass of hydrogen, kg/kmol\n", + "\n", + "#Calculations\n", + "a=(aa+ab)/2; #effective molecular diameter for collisions of hydrogen and air,m\n", + "b=math.sqrt(b1*b2); #effective potential well depth,K\n", + "c=T1/b; \n", + "\n", + "d=0.8822; #potential well function, from table 11.3\n", + "Dab=(1.8583*math.pow(10,-7))*math.pow(T1,1.5)/(math.pow(a,2)*d)*math.sqrt(1/Mh+1/Ma); #diffusion coefficient of hydrogen in air,m**2/s\n", + "\n", + "\n", + "#Result\n", + "print \"Diffusion coefficient of hydrogen in air is :\",round(Dab,6),\"m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\\n\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Diffusion coefficient of hydrogen in air is : 6.6e-05 m^2/s an experimental value from table is 6.34*10^-5 m^2/s,so the prediction is high by 5 percent.\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.4, Page number: 625" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "\n", + "#Variables\n", + "T1=373.15; #temp.of tea,K\n", + "XN2=0.7808; #mole fraction of nitrogen\n", + "XO2=0.2095; #mole fraction of oxygen\n", + "Xar=0.0093; #mole fraction of\n", + "Cp=1006 #mixture diffusivity,j/(kg*K)\n", + "\n", + "#Calculations\n", + "a=array(([3.798, 3.467, 3.542])); #collisin diameter,m\n", + "b=array(([71.4, 106.7, 93.3])); #lennard jones constant,K\n", + "M=array(([28.02, 32, 39.95])); #molar masses,kg/kmol\n", + "c=array(([0.9599, 1.057, 1.021])); #potential well function\n", + "d=array(([1.8*10**-5, 2.059*10**-5, 2.281*10**-5])); #calculated viscosity,kg/(m*s)\n", + "e=array(([1.8*10**-5, 2.07*10**-5, 2.29*10**-5])); # theoritical viscosity,kg/(m*s)\n", + "f=array(([0.0260, 0.02615, 0.01787])); #theoritical thermal conducitvity,W/(m*K)\n", + "\n", + "u=2.6693*10**-6*(M*T1)**0.5/((a**2*c)); #viscosity,kg/(m*s)\n", + "k=0.083228/((a**2*c*(T1/M**0.5))) #thermal conductivity,W/(m*s)\n", + "umc = XN2*u.item(0)/0.9978+XO2*u.item(1)/1.008+Xar*u.item(2)/0.9435 ; #calculated mixture viscosity,kg/(m*s)\n", + "umc1=1.857*10**-5;\n", + "\n", + "umd=XN2*e.item(0)/0.9978+XO2*e.item(1)/1.008+e.item(2)*Xar/0.9435; #theoritical mixture viscosity,kg/(m*s)\n", + "kmc=XN2*k.item(0)/0.9978+XO2*k.item(1)/1.008+Xar*k.item(2)/0.9435; #calculated thermal conducitvity,W/(m*K)\n", + "kmc1=0.02623;\n", + "kmd=XN2*f.item(0)/0.9978+XO2*f.item(1)/1.008+Xar*f.item(2)/0.9435; #theoritical thermal conductivity, W/(m*K)\n", + "pr=umd*Cp/kmd; #prandtl no.\n", + "\n", + "#Result\n", + "print \"Theoritical mixture viscosity is :\",round(umc1,6),\"kg/(m*s)\\n\"\n", + "print \"Calculated mixture viscosity is :\",round(umd,6),\"kg/(m*s)\\n\"\n", + "print \"Theoritical thermal conducitvity is :\",round(kmc1,4),\" W/(m*K)\\n\"\n", + "print \"Calculated thermal conducitvity is :\",round(kmd,4),\"W/(m*K)\\n\" \n", + "print \"Prandtl no. is :\",round(pr,4),\"\\n\"\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Theoritical mixture viscosity is : 1.9e-05 kg/(m*s)\n", + "\n", + "Calculated mixture viscosity is : 1.9e-05 kg/(m*s)\n", + "\n", + "Theoritical thermal conducitvity is : 0.0262 W/(m*K)\n", + "\n", + "Calculated thermal conducitvity is : 0.026 W/(m*K)\n", + "\n", + "Prandtl no. is : 0.7214 \n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.5, Page number: 632" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "from numpy import array\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "#Variables\n", + "Patm=101.325;\t\t\t#Atmospheric pressure in kPa.\n", + "Mh20=18.02;\t\t\t\t#Molecular mass of H20 in kg/kmol.\n", + "Mair=28.96;\t\t\t\t#Molecular mass of air in kg/kmol.\n", + "Psat =array(([0.6113, 1.2276, 2.3385, 4.2461, 7.3837, 12.35, 19.941, 31.188, 47.39, 70.139, 101.325]));\t\t#Saturated pressure of watrer in kPa \n", + "T=array(([0.01, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]));\t\t#Temperature of air in in degree C\n", + "#Calculations\n", + "xw=Psat/Patm;\t\t\t\t\n", + "\n", + "mw=(xw*Mh20)/(xw*Mh20+(1-xw)*Mair);\t\t#Mass fraction of water vapour.\n", + "#Result\n", + "plt.plot(T,mw);\n", + "plt.xlabel(\"Temperature(Degree C)\")\n", + "plt.ylabel(\"Mass fraction of water vapour\");\n", + "plt.show()\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "display_data", + "png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEPCAYAAACp/QjLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVPX+P/AXmxtq5o5AoYDsIrglipKGmIqlmeJ2FQnJ\n3ErrV997b4bZ1bzebql071UrLRfEyBtmSqaCuYCWqJB4U1QScMOdRbbh8/vjxAiyzDBw5swwr+fj\nMQ+YmTOf855Tnjef3UwIIUBERFSJudIBEBGR4WFyICKiapgciIioGiYHIiKqhsmBiIiqYXIgIqJq\nZE0Os2bNQpcuXeDl5VXrMQsWLICzszO8vb1x6tQpOcMhIiItyZocQkNDER8fX+v7e/bsQUZGBi5c\nuID169djzpw5coZDRERakjU5+Pv748knn6z1/V27dmHGjBkAgAEDBuDevXu4ceOGnCEREZEWFO1z\nyMnJgb29vfq5nZ0dsrOzFYyIiIgAA+iQfnz1DjMzM4UiISKiCpZKntzW1hZZWVnq59nZ2bC1ta12\nnJOTEy5evKjP0IiIjJ6joyMyMjJ0+qyiNYexY8fiq6++AgAkJyejXbt26NKlS7XjLl68CCEEH0Lg\nvffeUzwGQ3nwWvBa8FrU/FixQmD2bNGgP6plrTlMnjwZhw4dwq1bt2Bvb4+lS5eitLQUABAREYFR\no0Zhz549cHJygrW1NTZu3ChnOERETZ4QwObNwLp1wPr1upcja3KIjo7WeExUVJScIRARmZQzZ4DC\nQsDPr2HlKN4hTfUTEBCgdAgGg9fiEV6LR0z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uLrKws9fOsrCzY\n2dlVOebkyZMICQkBANy6dQt79+6FlZUVxo4dW628yMhI9e8BAQEICAjQGAMREQDMmydNePP1VToS\neSUmJiIxMbFRytLYIX3nzh289957OHr0KADA398fkZGRePLJJ+ssuKysDC4uLjhw4AC6deuG/v37\n19ghXSE0NBTBwcEYP3589SDZIU1EOvrmG2nY6unTgJ43sVScrJPg2rdvj7Vr19a/YEtLREVFISgo\nCCqVCmFhYXBzc8O6desAABEREfWPloioHu7cAebPB77+2vQSQ0PVWnNYuHAhVq9ejeDg4OofMjPD\nrl27ZA+u8vlYcyCi+poxA2jXDli9WulIlCFLzeFPf/oTAGDx4sU1npCIyJDt3QscPswNfHRVa3Lo\n06cPAOD06dN4/fXXq7z3ySefYOjQofJGRkSkowcPgFdfBT7/HGjdWulojJPGDmkfHx+cOnWqymu9\ne/fG6dOnZQ2sMjYrEVF9vPaatMPbZ58pHYmyZGlWio6OxrZt23D58uUq/Q55eXmKLt9NRFSXxERg\n1y5Ai4UcqA61Jgc/Pz/Y2NggNzcXb775pjr7tG3bFr169dJbgERE2ioslFZc/de/pI5o0p3GZqVL\nly7BxsYGLVu2BAA8fPgQN27cgIODgz7iA8BmJSLSTAhg7lzg7l0gOlrpaAyDrAvvTZw4scr2oObm\n5pgwYYJOJyMikoNKJXVAnzgBREUpHU3ToHESXFlZmXqTHwBo3rw5SktLZQ2KiEhbRUXAlClAXh6Q\nkABouasAaaCx5tCxY8cqS23HxcWhY8eOsgZFRKSN+/eBkSOBZs2k/aCZGBqPxj6HjIwMTJ06FVev\nXgUgLb29efNmODk56SVAgH0ORFTd9evA888DgwdLM6C5F3R1Dbl31msnODMzM7RWYEYJkwMRVXbx\nIhAUJC2P8de/Aly0oWayLrwHALt370Z6ejqKiorUry1ZskSnExIRNcSpU8CYMcCSJdLObiQPjckh\nIiICDx8+xMGDBxEeHo6vv/4aAwYM0EdsRERVJCYCEycC//43UMN289SINDYreXl5IS0tDb169UJq\nairy8/MxcuRIHDlyRF8xsl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AuLk7v5yXlseZARETVsM+BiIiqYXIgIqJq\nmByIiKgaJgciIqqGyYGIiKphciAiomr+P6Ksmp778+IaAAAAAElFTkSuQmCC\n", + "text": [ + "" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.6, Page number: 634" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=263.15; #temp.of ice,K\n", + "p=101.325; #Atmospheric pressure, KPa\n", + "Molw=18.02; #Molecular mass of water vapour, g/mol\n", + "Mola=28.96; #Molecular mass of air, g/mol\n", + "\n", + "#Calculations\n", + "Pv=math.exp(21.99-6141/(T1)); #vapor pressure,KPa\n", + "xw=Pv/p; #mole fraction of water\n", + "mw=xw*Molw/(xw*Molw+(1-xw)*Mola); #mass fraction\n", + "\n", + "#Result\n", + "print \"Mass fraction of watervapor above the surface of ice is :\",round(mw,5),\"\\n\"\n", + "#end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mass fraction of watervapor above the surface of ice is : 0.0016 \n", + "\n" + ] + } + ], + "prompt_number": 26 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.10, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=303; # isothermal temp.,K\n", + "v=5; #air speed,m/s\n", + "l=0.05; #length of naphthalene model that is flat, m\n", + "Mnap=128.2; #molar mass of naphthalene,kg/kmol\n", + "nu=1.867*10**-5; #Dynamic viscocity, m^2/s\n", + "\n", + "#Calculations\n", + "D=0.86*(10**-5); #diffusion coefficient of naphthalene in air,m/s\n", + "\n", + "Pv=10**(11.45-3729.3/T1)*133.31; #vapor pressure of napthalene, Pa\n", + "xn=Pv/101325; #mole fraction of naphthalene\n", + "mn=xn*Mnap/(xn*Mnap+(1-xn)*28.96); #mass fraction of naphthalene\n", + "mnp=0; #mass fraction of naphthalene in free stream is 0\n", + "\n", + "Rel=v*l/nu; #reynolds no.\n", + "Sc=nu/D; #schimidt no.\n", + "Nul=0.664*math.sqrt(Rel)*(Sc**(1/3)); #mass transfer nusselt no.\n", + "Gmn=D*Nul*1.166/l; #gas phase mass transfer coefficient,kg/(m**2*s)\n", + "n=Gmn*(mn-mnp); #average mass flux,kg/(m**2*s)\n", + "n1=n*1000*3600;# average mass flux, g/m**2.h\n", + "\n", + "#Result\n", + "print \"Average rate of loss of naphthalene from a part of model is :\",round(n,7),\"kg/(m^2*s) or \",round(n1),\"g/(m^2*h)\\n\"\n", + "print \"Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\\n\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average rate of loss of naphthalene from a part of model is : 1.61e-05 kg/(m^2*s) or 58.0 g/(m^2*h)\n", + "\n", + "Naphthalene sublimatin can be used to infer heat transfer coefficient by measuring the loss of naphthalene from a model over some length of time.since the schimidt no. of naphthalene is not generally equal to prandtl no. under the conditions of interest, some assumption about the dependence of nusselt no. on the prandtl no. must usually be introduced.\n", + "\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.11, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=300; #temp. of helium-water tube,K\n", + "h=0.4; #height of vertical wall,m\n", + "m=0.087*10**-3; #flow rate of helium,kg/(m**2*s)\n", + "#this is a uniform flux natural convection problem.\n", + "Mhes=0.01; # assuming the value of mass fraction of helium at the wall to be 0.01\n", + "Mhef=Mhes/2; #film composition\n", + "af=1.141; #film density,kg/m**3\n", + "wd=1.107; #wall density,kg/m**3\n", + "Dha=7.119*10**-5; #diffusion coefficient,m**2/s\n", + "u=1.857*10**-5; #film viscosity at 300K,kg/(m*s)\n", + "aa=1.177; #air density,kg/m**3\n", + "g=9.8; #Gravity constant, m/s**2\n", + "#Calculations\n", + "Sc=(u/af)/Dha; #schimidt no.\n", + "Ra1=g*(aa-wd)*m*h**4/(u*af*Dha**2*Mhes); #Rayleigh no.\n", + "Nu=6/5*(Ra1*Sc/(4+9*math.sqrt(Sc)+10*Sc))**(1/5); #approximate nusselt no.\n", + "s=m*h/(af*Dha*Nu); #average concentration of helium at the wall\n", + "#thus we have obtained an average wall concentration 14 oercent higher than our initial guess of Mhes.we repeat this calclations with revised values of densities to obtain Mhes = 0.01142\n", + "\n", + "\n", + "#Result\n", + "print \"Average conentration of helium at the wall is \",round(s,5),\",since the result is within 0.5 percent of our second guess, a third iteration is not needed\"\n", + " #end\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average conentration of helium at the wall is 0.01136 ,since the result is within 0.5 percent of our second guess, a third iteration is not needed\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.14, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=325; #temp. of helium-water tube,K\n", + "l=0.2; #length of tube,m\n", + "x=0.01; # mole fraction of water\n", + "R=8314.472; #gas constant,J/(kmol*K)\n", + "Mw=18.02;#Molecular mass of water, g/mol\n", + "#the vapor pressure of the liquid water is approximately the saturation pressure at the water temp.\n", + "\n", + "#Calculations\n", + "p=1.341*10000 ; #vapor pressure using steam table,Pa\n", + "x1=p/101325; #mole fraction of saturated water\n", + "c=101325/(R*T1); #mole concentration in tube,kmol/m**3\n", + "D12=1.067*math.pow(10,-4); #diffusivity ofwater with respect to helium,m**2/s \n", + "Nw=c*D12*math.log(1+(x-x1)/(x1-1))/l ; #molar evaporation rate,kmol/(m**2*s)\n", + "nw=Nw*Mw; # mass evaporation rate,kg/(m**2*s)\n", + "\n", + "#S=1+(x1-1)*math.exp(Nw*y/(c*D12)) conentration distribution of water-vapor\n", + "#Result\n", + "print \"Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Conentration distribution of water-vapor is : x1(y)=1-0.8677*exp(0.6593*y) where y is expressed in meters.\n", + "\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.15, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "\n", + "#Variables\n", + "T1=1473; #suraface temp.of hot water,K\n", + "x=0.05; #mass fraction of water\n", + "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", + "A=0.04; #suraface area of pan,m**2\n", + "\n", + " #only water vapour passes through the liquid surface, since air is not strongly absorbed into water under normal conditions.\n", + "#Calculations\n", + "p=38.58*1000; #saturation pressure of water,kPa\n", + "Xwater=p/101325; #mole fraction of saturated water\n", + "Mwater=Xwater*18.02/(Xwater*18.02+(1-Xwater)*28.96); #mass fraction of saturated water\n", + "\n", + "B=(x-Mwater)/(Mwater-1); #mass transfer driving force\n", + "m=Gm*B*A; #evaporation rate,kg/s\n", + "\n", + "#Result\n", + "print \"Evaporation rate is:\",round(m,6),\" kg/s\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Evaporation rate is: 0.000213 kg/s\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 11.16, Page number:" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "import math\n", + "\n", + "#Variables\n", + "T1=298; #temp.of air,K\n", + "T2=323.15; #film temp.,K\n", + "x=0.05; #mass fraction of water at 75 C\n", + "Gm=0.017; #average mass transfer coefficient,kg/(m**2*s)\n", + "A=0.04; #suraface area of pan,m**2\n", + "l=0.2; #length of pan in flow direction,m\n", + "v=5; #air speed,m/s\n", + "m=(x+0.277)/2; #film composition of water at 50 C\n", + "Mf=26.34; #mixture molecular weight,kg/kmol\n", + "p=101325; #Atmospheric pressure, Pa\n", + "R=8314.5; #Gas constant, J/kmol-K\n", + "Uf=1.75*math.pow(10,-5); #film viscosity,kg/(m*s)\n", + "B=0.314; #mass transfer driving force\n", + "D=2.96*math.pow(10,-5); #diffusivity of water in air,m**2/s\n", + "df=0.993; #Density of ideal air, kg/m**#\n", + "\n", + "#Calculations\n", + "af=p*Mf/(R*T2); \t #film density from ideal gas law,kg/m**3\n", + "Vf=Uf/af; #kinematic viscosity,m**2/s\n", + "Rel=v*l/Vf; #reynolds no. comes out to be 56,800 so the flow is laminar.\n", + "Sc=Vf/D; #scimidt no.\n", + "Nu=0.664*math.sqrt(Rel)*math.pow(Sc,1/3); #nussselt no.\n", + "Gmw1=Nu*(D*df/l); #appropriate value of mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", + "Gmw=Gmw1*(math.log(1+B)/B); \t #mass transfer gas phase coeffficient of water in air,kg/(m**2*s)\n", + "\n", + "#Results\n", + "print \"Mass transfer gas phase coeffficient of water in air is :\",round(Gmw,4),\"kg/(m^2*s)\\nIn this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.01955648559 133.069905487\n", + "Mass transfer gas phase coeffficient of water in air is : 0.017 kg/(m^2*s)\n", + "In this caes, the blowing factor is 0.870. Thus the mild blowing has reduced the mass transfer coefficient by about 13 percent\n" + ] + } + ], + "prompt_number": 28 + } + ], + "metadata": {} + } + ] } \ No newline at end of file diff --git a/Beginning_C++_Through_Game_Programming/.ipynb_checkpoints/ch10-checkpoint.ipynb b/Beginning_C++_Through_Game_Programming/.ipynb_checkpoints/ch10-checkpoint.ipynb new file mode 100755 index 00000000..000367d6 --- /dev/null +++ b/Beginning_C++_Through_Game_Programming/.ipynb_checkpoints/ch10-checkpoint.ipynb @@ -0,0 +1,642 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 10 : Inheritance and Polymorphism: Blackjack" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.1 page no: 334" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Enemy:\n", + " def __init__(self):\n", + " self.m_Damage = 10\n", + "\n", + " def Attack(self):\n", + " print \"An enemy attacks and inflicts \" , self.m_Damage , \" damage points!\";\n", + " \n", + " def __del__(self):\n", + " print \"In Enemy destructor, deleting m_pDamage.\\n\";\n", + "\n", + "class Boss(Enemy):\n", + " def __init__(self):\n", + " Enemy.__init__(self)\n", + " self.m_DamageMultiplier = 3\n", + "\n", + " def SpecialAttack(self):\n", + " print \"A boss attacks and inflicts \" , (self.m_DamageMultiplier * self.m_Damage),\n", + " print \" damage points!\";\n", + "\n", + "print \"Creating an enemy.\\n\";\n", + "enemy1 = Enemy()\n", + "enemy1.Attack();\n", + "print \"\\nCreating a boss.\\n\";\n", + "boss1 = Boss()\n", + "boss1.Attack();\n", + "boss1.SpecialAttack();" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Creating an enemy.\n", + "\n", + "An enemy attacks and inflicts 10 damage points!\n", + "\n", + "Creating a boss.\n", + "\n", + "An enemy attacks and inflicts 10 damage points!\n", + "A boss attacks and inflicts 30 damage points!\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.2 page no : 338" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "class Enemy:\n", + " def __init__(self):\n", + " self.m_Damage = 10\n", + "\n", + " def Attack(self):\n", + " print \"Attack inflicts \" , self.m_Damage , \" damage points!\";\n", + "\n", + "class Boss(Enemy):\n", + " def __init__(self):\n", + " Enemy.__init__(self)\n", + " self.m_DamageMultiplier = 3\n", + "\n", + " def SpecialAttack(self):\n", + " print \"Special Attack inflicts \" , (self.m_DamageMultiplier * self.m_Damage),\n", + " print \" damage points!\";\n", + "\n", + "print \"Creating an enemy.\\n\";\n", + "enemy1 = Enemy()\n", + "enemy1.Attack();\n", + "print \"\\nCreating a boss.\\n\";\n", + "boss1 = Boss()\n", + "boss1.Attack();\n", + "boss1.SpecialAttack();" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Creating an enemy.\n", + "\n", + "Attack inflicts 10 damage points!\n", + "\n", + "Creating a boss.\n", + "\n", + "Attack inflicts 10 damage points!\n", + "Special Attack inflicts 30 damage points!\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.3 page no : 343" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Enemy:\n", + " def __init__(self,d=10):\n", + " self.m_Damage = d\n", + "\n", + " def Attack(self):\n", + " print \"Attack inflicts \" , self.m_Damage , \" damage points!\";\n", + "\n", + " def Taunt(self):\n", + " print \"The enemy says he will fight you.\";\n", + " __Attack = Attack \n", + "\n", + "\n", + "class Boss(Enemy):\n", + " def __init__(self,d=30):\n", + " Enemy.__init__(self)\n", + " self.m_DamageMultiplier = d\n", + "\n", + " def SpecialAttack(self):\n", + " print \"Special Attack inflicts \" , (self.m_DamageMultiplier * self.m_Damage),\n", + " print \" damage points!\";\n", + "\n", + " def Taunt(self): #override base class member function\n", + " print \"The boss says he will end your pitiful existence.\"\n", + "\n", + " def Attack(self): #override base class member function\n", + " #call base class member function\n", + " Enemy.Attack(self)\n", + " print \" And laughs heartily at you.\\n\";\n", + "\n", + "\n", + "print \"Enemy object :\";\n", + "enemy1 = Enemy()\n", + "enemy1.Taunt()\n", + "enemy1.Attack();\n", + "print \"\\n boss object.\\n\";\n", + "boss1 = Boss()\n", + "boss1.Taunt()\n", + "boss1.Attack();\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enemy object :\n", + "The enemy says he will fight you.\n", + "Attack inflicts 10 damage points!\n", + "\n", + " boss object.\n", + "\n", + "The boss says he will end your pitiful existence.\n", + "Attack inflicts 10 damage points!\n", + " And laughs heartily at you.\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.4 page no : 341,348" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Enemy:\n", + " def __init__(self,d=10):\n", + " self.m_Damage = d\n", + "\n", + " def Attack(self):\n", + " print \"Attack inflicts \" , self.m_Damage , \" damage points!\";\n", + "\n", + " def __del__(self):\n", + " print \"In Enemy destructor, deleting m_pDamage.\";\n", + " \n", + "class Boss(Enemy):\n", + " def __init__(self,d=30):\n", + " Enemy.__init__(self)\n", + " self.m_DamageMultiplier = d\n", + "\n", + " def SpecialAttack(self):\n", + " print \"Special Attack inflicts \" , (self.m_DamageMultiplier * self.m_Damage),\n", + " print \" damage points!\";\n", + "\n", + " def Taunt(self): #override base class member function\n", + " print \"The boss says he will end your pitiful existence.\"\n", + "\n", + " def Attack(self): #override base class member function\n", + " #call base class member function\n", + " Enemy.Attack(self)\n", + " print \" And laughs heartily at you.\\n\";\n", + "\n", + " def __del__(self):\n", + " Enemy.__del__(self)\n", + " print \"In Boss destructor, deleting m_pMultiplier.\";\n", + " self.m_pMultiplier = 0;\n", + "\n", + "print \"Calling Attack() on Boss object through pointer to Enemy:\"\n", + "pBadGuy = Boss();\n", + "pBadGuy.Attack();\n", + "print \"\\nDeleting pointer to Enemy:\\n\";\n", + "pBadGuy = 0;" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Calling Attack() on Boss object through pointer to Enemy:\n", + "Attack inflicts 10 damage points!\n", + " And laughs heartily at you.\n", + "\n", + "\n", + "Deleting pointer to Enemy:\n", + "\n", + "In Enemy destructor, deleting m_pDamage.\n", + "In Boss destructor, deleting m_pMultiplier.\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.5 page no : 353" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Creature :\n", + " def __init__(self,h=100):\n", + " self.m_Health = h\n", + " \n", + " def Greet(self): # pure virtual member function\n", + " pass\n", + "\n", + " def DisplayHealth(self):\n", + " print \"Health: \" , self.m_Health\n", + "\n", + "\n", + "class Orc(Creature):\n", + " def __init__(self,h=120):\n", + " Creature.__init__(self,h)\n", + "\n", + " def Greet(self):\n", + " print \"The orc grunts hello.\\n\";\n", + "\n", + "pCreature = Orc();\n", + "pCreature.Greet();\n", + "pCreature.DisplayHealth();" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The orc grunts hello.\n", + "\n", + "Health: 120\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 10.6, page no : 361-379" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "ACE = 1\n", + "TWO = 2\n", + "THREE = 3\n", + "FOUR = 4\n", + "FIVE = 5\n", + "SIX = 6\n", + "SEVEN = 7\n", + "EIGHT = 8\n", + "NINE = 9\n", + "TEN = 10\n", + "JACK = 11\n", + "QUEEN = 12\n", + "KING = 13\n", + "\n", + "CLUBS = 0\n", + "DIAMONDS = 1\n", + "HEARTS = 2\n", + "SPADES = 3\n", + "\n", + " \n", + "class Card:\n", + " def __init__(self,r = ACE,s = SPADES,ifu = True): #returns the value of a card, 1 - 11\n", + " self.m_Rank = r\n", + " self.m_Suit = s\n", + " self.m_IsFaceUp =ifu\n", + "\n", + " def GetValue(self):\n", + " #if a cards is face down, its value is 0\n", + " value = 0;\n", + " if (m_IsFaceUp):\n", + " #value is number showing on card\n", + " value = m_Rank;\n", + " #value is 10 for face cards\n", + " if (value > 10):\n", + " value = 10;\n", + " return value;\n", + "\n", + " def Flip(self):\n", + " self.m_IsFaceUp = not (self.m_IsFaceUp);\n", + "\n", + "class Hand:\n", + " def __init__(self):\n", + " self.m_Cards = []\n", + "\n", + " def __del__(self):\n", + " self.Clear() \n", + "\n", + " def Add(self,pCard):\n", + " self.m_Cards.append(pCard);\n", + "\n", + " def Clear(self):\n", + " #iterate through vector, freeing all memory on the heap\n", + " self.m_Cards = []\n", + "\n", + " def GetTotal(self):\n", + " #if no cards in hand, return 0\n", + " if (self.m_Cards.empty()):\n", + " return 0;\n", + " #if a first card has value of 0, then card is face down; return 0\n", + " if (self.m_Cards[0].GetValue() == 0):\n", + " return 0;\n", + " #add up card values, treat each ace as 1\n", + " total = 0;\n", + " for i in self.m_Cards:\n", + " total += i.GetValue()\n", + " #determine if hand contains an ace\n", + " containsAce = False;\n", + " for i in self.m_Cards:\n", + " if i.GetValue() == Card.ACE:\n", + " containsAce = True;\n", + "\n", + " #if hand contains ace and total is low enough, treat ace as 11\n", + " if (containsAce and total <= 11):\n", + " #add only 10 since we've already added 1 for the ace\n", + " total += 10;\n", + " return total;\n", + "\n", + "\n", + "class GenericPlayer(Hand):\n", + " def __init__(self,name):\n", + " self.m_Name = name\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def IsBusted(self):\n", + " return (self.GetTotal() > 21);\n", + "\n", + " def Bust(self):\n", + " print self.m_Name , \" busts.\";\n", + "\n", + "class Player(GenericPlayer):\n", + " def _init_(self,name):\n", + " GenericPlayer.__init__(self,name)\n", + " \n", + " def _del_(self):\n", + " pass\n", + "\n", + " def IsHitting(self):\n", + " print self.m_Name , \", do you want a hit? (Y/N): \",\n", + " response = raw_input()\n", + " return (response == 'y' or response == 'Y');\n", + "\n", + " def Win(self):\n", + " print self.m_Name , \" wins.\";\n", + "\n", + " def Lose(self):\n", + " print self.m_Name , \" loses.\";\n", + "\n", + " def Push(self):\n", + " print self.m_Name , \" pushes.\";\n", + "\n", + "class House(GenericPlayer):\n", + " def __init__(self,name=\"House\"):\n", + " GenericPlayer.__init__(self,name)\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def IsHitting(self):\n", + " return (self.GetTotal() <= 16)\n", + "\n", + " def FlipFirstCard(self):\n", + " if (not self.m_Cards):\n", + " self.m_Cards[0].Flip();\n", + " else:\n", + " print \"No card to flip!\";\n", + " \n", + "class Deck(Hand):\n", + " def __init__(self):\n", + " self.m_Cards = []\n", + " self.Populate();\n", + " \n", + " def __del__(self):\n", + " pass\n", + " \n", + " def Populate(self):\n", + " self.Clear();\n", + " #create standard deck\n", + " for s in range(CLUBS,SPADES+1):\n", + " for r in range(ACE,KING+1):\n", + " self.Add(Card(r,s))\n", + "\n", + " def Shuffle(self):\n", + " pass\n", + "\n", + " def Deal(self, aHand):\n", + " if (not self.m_Cards):\n", + " aHand.Add(self.m_Cards[-1]);\n", + " self.m_Cards.pop();\n", + " else:\n", + " print \"Out of cards. Unable to deal.\";\n", + "\n", + " def AdditionalCards(self,aGenericPlayer):\n", + " print ''\n", + " #continue to deal a card as long as generic player isn't busted and\n", + " #wants another hit\n", + " while ( not (aGenericPlayer.IsBusted()) and aGenericPlayer.IsHitting() ):\n", + " self.Deal(aGenericPlayer);\n", + " print aGenericPlayer\n", + " if (aGenericPlayer.IsBusted()):\n", + " aGenericPlayer.Bust();\n", + " \n", + "\n", + "class Game:\n", + " def __init__(self,names):\n", + " #create a vector of players from a vector of names\n", + " self.m_Players = []\n", + " for i in names:\n", + " self.m_Players.append(Player(i))\n", + " self.m_Deck = Deck()\n", + " self.m_House = House()\n", + " self.m_Deck.Populate();\n", + " self.m_Deck.Shuffle();\n", + "\n", + " def __del__(self):\n", + " pass\n", + " \n", + " def Play(self):\n", + " # deal initial 2 cards to everyone\n", + " for i in range(2):\n", + " for pPlayer in self.m_Players:\n", + " self.m_Deck.Deal(pPlayer);\n", + " self.m_Deck.Deal(self.m_House);\n", + " #hide house's first card\n", + " self.m_House.FlipFirstCard();\n", + " for pPlayer in self.m_Players:\n", + " print pPlayer \n", + "\n", + " print self.m_House\n", + " #deal additional cards to players\n", + " \n", + " for pPlayer in self.m_Players:\n", + " self.m_Deck.AdditionalCards(pPlayer);\n", + "\n", + " #reveal house's first card\n", + " self.m_House.FlipFirstCard();\n", + " print self.m_House;\n", + " #deal additional cards to house\n", + " self.m_Deck.AdditionalCards(m_House);\n", + " if (self.m_House.IsBusted()):\n", + " #everyone still playing wins\n", + " for pPlayer in self.m_Players:\n", + " if ( not (pPlayer.IsBusted()) ):\n", + " pPlayer.Win();\n", + " else:\n", + " #compare each player still playing to house\n", + " for pPlayer in self.m_Players:\n", + " if ( not (pPlayer.IsBusted()) ):\n", + " if (pPlayer.GetTotal() > self.m_House.GetTotal()):\n", + " pPlayer.Win();\n", + " elif (pPlayer.GetTotal() < self.m_House.GetTotal()):\n", + " pPlayer.Lose();\n", + " else:\n", + " pPlayer.Push();\n", + "\n", + " #remove everyones cards\n", + " for pPlayer in self.m_Players:\n", + " pPlayer.Clear();\n", + "\n", + " self.m_House.Clear();\n", + "\n", + "print \"\\t\\tWelcome to Blackjack!\\n\";\n", + "numPlayers = 0;\n", + "while (numPlayers < 1 or numPlayers > 7):\n", + " print \"How many players? (1 - 7): \";\n", + " numPlayers = int(raw_input())\n", + "\n", + "names = []\n", + "name = ''\n", + "for i in range(numPlayers):\n", + " print \"Enter player name: \";\n", + " name = raw_input()\n", + " names.append(name); \n", + "\n", + "print ''\n", + "#the game loop\n", + "aGame = Game(names);\n", + "again = 'y'\n", + "while (again != 'n' and again != 'N'):\n", + " aGame.Play();\n", + " print \"\\nDo you want to play again? (Y/N): \",\n", + " again = raw_input()\n", + "\n", + "#overloads << operator so Card object can be sent to cout\n", + "def print_(aCard):\n", + " RANKS = [\"0\", \"A\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\",\"10\", \"J\", \"Q\", \"K\"]\n", + " SUITS = [\"c\", \"d\", \"h\", \"s\"]\n", + " if (aCard.m_IsFaceUp):\n", + " print RANKS[aCard.m_Rank] , SUITS[aCard.m_Suit];\n", + " else:\n", + " print \"XX\";\n", + " \n", + "\n", + "def print__(aGenericPlayer):\n", + " print aGenericPlayer.m_Name\n", + " pCard = []\n", + " if (not aGenericPlayer.m_Cards):\n", + " for pCard in aGenericPlayer.m_Cards:\n", + " print pCard\n", + " \n", + " if (aGenericPlayer.GetTotal() != 0):\n", + " print \"(\" , aGenericPlayer.GetTotal() , \")\";\n", + " else:\n", + " print \"\";\n", + " \n", + "# Note : this example is just for concept purpose. i.e. Inheritance example. it has errors so do not run it \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t\tWelcome to Blackjack!\n", + "\n", + "How many players? (1 - 7): \n" + ] + } + ], + "prompt_number": "*" + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Beginning_C++_Through_Game_Programming/ch10.ipynb b/Beginning_C++_Through_Game_Programming/ch10.ipynb index e3ec6373..000367d6 100755 --- a/Beginning_C++_Through_Game_Programming/ch10.ipynb +++ b/Beginning_C++_Through_Game_Programming/ch10.ipynb @@ -623,80 +623,17 @@ "\n", "How many players? (1 - 7): \n" ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter player name: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "John\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter player name: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Mark\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter player name: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Peter\n" - ] - }, - { - "ename": "AttributeError", - "evalue": "Game instance has no attribute 'm_Deck'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 236\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m''\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 237\u001b[0m \u001b[1;31m#the game loop\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 238\u001b[1;33m \u001b[0maGame\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mGame\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnames\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 239\u001b[0m \u001b[0magain\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'y'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 240\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0magain\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;34m'n'\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0magain\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;34m'N'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, names)\u001b[0m\n\u001b[0;32m 171\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mnames\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 172\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpName\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mPlayer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 173\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mm_Deck\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPopulate\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\u001b[0;32m 174\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mm_Deck\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mShuffle\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 175\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mAttributeError\u001b[0m: Game instance has no attribute 'm_Deck'" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] } ], - "prompt_number": 1 + "prompt_number": "*" + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] } ], "metadata": {} diff --git a/Beginning_C_By_Ivon_Horton/chapter13.ipynb b/Beginning_C_By_Ivon_Horton/chapter13.ipynb index 6169215b..48685d3a 100755 --- a/Beginning_C_By_Ivon_Horton/chapter13.ipynb +++ b/Beginning_C_By_Ivon_Horton/chapter13.ipynb @@ -28,8 +28,6 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", - "\n", "y = 5\n", "for x in range(20):\n", " print \"x = %d y = %d\" %(x, y)\n", @@ -43,9 +41,9 @@ "evalue": "", "output_type": "pyerr", "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m20\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[1;32mprint\u001b[0m \u001b[1;34m\"x = %d y = %d\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m \u001b[1;33m<\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;31mAssertionError\u001b[0m: " + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"x = %d y = %d\"\u001b[0m \u001b[0;34m%\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32massert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAssertionError\u001b[0m: " ] }, { @@ -61,7 +59,7 @@ ] } ], - "prompt_number": 1 + "prompt_number": 2 }, { "cell_type": "heading", diff --git a/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter13-checkpoint.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter13-checkpoint.ipynb new file mode 100755 index 00000000..8c87053f --- /dev/null +++ b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter13-checkpoint.ipynb @@ -0,0 +1,412 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:60c23a8f50ffb51e0da71a6e8b36475b7941871a6f534003180327a651bb1c1c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13: Persistent Data: File Input and Output" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.1, page no. 296" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "try:\n", + " if(fp):\n", + " print \"infile = \", fp\n", + " print \"0\"\n", + "except IOError:\n", + " print \"1\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.2, page no. 296" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "try:\n", + " fp = open(\"students.dat\", \"w\")\n", + " if(fp):\n", + " print \"infile = \", fp\n", + " print \"0\"\n", + "except IOError:\n", + " print \"1\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "infile = \n", + "0\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.3, page no. 299" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "fp = open(\"students.dat\", \"w\")\n", + "print \"Writing to the file\"\n", + "print \"===================\"\n", + "print \"Enter class name: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.write(\"\\n\")\n", + "print \"Enter number of students: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Writing to the file\n", + "===================\n", + "Enter class name: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "C++\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter number of students: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.4, page no. 301" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "fp = open(\"students.dat\", \"w\")\n", + "print \"Writing to the file\"\n", + "print \"===================\"\n", + "print \"Enter class name: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.write(\"\\n\")\n", + "print \"Enter number of students: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.close()\n", + "fp = open(\"students.dat\", \"r\")\n", + "print \"Reading from the file\"\n", + "print \"=====================\"\n", + "lines = fp.readlines()\n", + "for line in lines:\n", + " print line\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Writing to the file\n", + "===================\n", + "Enter class name: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "C++\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter number of students: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Reading from the file\n", + "=====================\n", + "C++\n", + "\n", + "32\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "example 13.5, page no. 303" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "fp = open(\"students.dat\", \"w\")\n", + "print \"Writing to the file\"\n", + "print \"===================\"\n", + "print \"Enter class name: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.write(\"\\n\")\n", + "print \"Enter number of students: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.close()\n", + "fp = open(\"students.dat\", \"r\")\n", + "print \"Reading from the file\"\n", + "print \"=====================\"\n", + "lines = fp.readlines()\n", + "for line in lines:\n", + " print line\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Writing to the file\n", + "===================\n", + "Enter class name: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "C++\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter number of students: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Reading from the file\n", + "=====================\n", + "C++\n", + "\n", + "32\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.6, page no. 305" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "fp = open(\"students.dat\", \"w\")\n", + "print \"Writing to the file\"\n", + "print \"===================\"\n", + "print \"Enter class name: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.write(\"\\n\")\n", + "print \"Enter number of students: \",\n", + "data = raw_input()\n", + "fp.write(data)\n", + "fp.close()\n", + "fp = open(\"students.dat\", \"r\")\n", + "print \"Reading from the file\"\n", + "print \"=====================\"\n", + "while(fp.readline()):\n", + " print fp.readline()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Writing to the file\n", + "===================\n", + "Enter class name: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "C++\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter number of students: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Reading from the file\n", + "=====================\n", + "32\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter5-checkpoint.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter5-checkpoint.ipynb new file mode 100755 index 00000000..9dac1dd3 --- /dev/null +++ b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter5-checkpoint.ipynb @@ -0,0 +1,488 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:527aef20f7b40df168e6ff4a5ccb96d249aaf7c6743cc854ce1a221227ecfb75" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5 - Making Decisions: if and switch Statements" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.1, page no. 100" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "a = 4\n", + "b = 5\n", + "print a, \" > \", b, \" is \", (a > b)\n", + "print a, \" >= \", b, \" is \", (a >= b)\n", + "print a, \" == \", b, \" is \", (a == b)\n", + "print a, \" <= \", b, \" is \", (a <= b)\n", + "print a, \" < \", b, \" is \", (a < b)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4 > 5 is False\n", + "4 >= 5 is False\n", + "4 == 5 is False\n", + "4 <= 5 is True\n", + "4 < 5 is True\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.2, page no. 102" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter number of preregistered students: \",\n", + "total = int(raw_input())\n", + "print \"Enter number of students adding the course: \",\n", + "added = int(raw_input())\n", + "total = total + added\n", + "print \"Total number of students: \", total" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter number of preregistered students: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "30\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter number of students adding the course: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Total number of students: 33\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.3, page no. 104" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter a whole number: \",\n", + "num = int(raw_input())\n", + "if (num % 2 == 0):\n", + " print \"The number is even\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a whole number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The number is even\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.4, page no. 108" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter a whole number: \",\n", + "num = int(raw_input())\n", + "if (num % 2 == 0):\n", + " print \"The number is even\"\n", + "else:\n", + " print \"The number is odd\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a whole number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The number is odd\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.4, page no. 109" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter a whole number: \",\n", + "num = int(raw_input())\n", + "print \"The number is\", (\"even\" if num %2 == 0 else \"odd\")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a whole number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The number is even\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.6, page no. 112" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter your test score: \",\n", + "testScore = int(raw_input())\n", + "if (testScore >= 90 ):\n", + " print \"Your grade is an A\"\n", + "elif (testScore >= 80 ):\n", + " print \"Your grade is a B\"\n", + "elif (testScore >= 70 ):\n", + " print \"Your grade is a C\"\n", + "elif (testScore >= 60 ):\n", + " print \"Your grade is a D\"\n", + "else:\n", + " print \"Your grade is an F\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your test score: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "70\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Your grade is a C\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.7, page no. 115" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter your grade: \",\n", + "grade = raw_input()\n", + "\n", + "if grade == 'A':\n", + " print \"Your average must be between 90 - 100\"\n", + "elif grade == 'B':\n", + " print \"Your average must be between 80 - 89\"\n", + "elif grade == 'C':\n", + " print \"Your average must be between 70 - 79\"\n", + "elif grade == 'D':\n", + " print \"Your average must be between 60 - 69\"\n", + "else:\n", + " print \"Your average must be below 60\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your grade: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "D\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Your average must be between 60 - 69\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.8, page no. 118" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "print \"Enter your grade: \",\n", + "grade = raw_input()\n", + "\n", + "if grade == 'A' or grade == 'a':\n", + " print \"Your average must be between 90 - 100\"\n", + "elif grade == 'B' or grade == 'b':\n", + " print \"Your average must be between 80 - 89\"\n", + "elif grade == 'C' or grade == 'c':\n", + " print \"Your average must be between 70 - 79\"\n", + "elif grade == 'D' or grade == 'd':\n", + " print \"Your average must be between 60 - 69\"\n", + "else:\n", + " print \"Your average must be below 60\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your grade: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "d\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Your average must be between 60 - 69\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 5.9, page no. 119" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "print \"Choose your car\"\n", + "print \"S for Standard\"\n", + "print \"L for Leather Seats\"\n", + "print \"D for Leather Seats + Chrome Wheels\"\n", + "choice = raw_input()\n", + "print \"Extra features purchased\"\n", + "if choice == 'D':\n", + " print \"Chrome wheels\\n\"\n", + "elif choice == 'L':\n", + " print \"Leather seats\"\n", + "else:\n", + " print \"None selected\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Choose your car\n", + "S for Standard\n", + "L for Leather Seats\n", + "D for Leather Seats + Chrome Wheels\n" + ] + } + ], + "prompt_number": "*" + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter9-checkpoint.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter9-checkpoint.ipynb new file mode 100755 index 00000000..5b5e1ccb --- /dev/null +++ b/C++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter9-checkpoint.ipynb @@ -0,0 +1,1033 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:f0e84b29896f17b0ff44f8bccf20cf041a408375d83b3bc2290848ec54364369" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9 - Functions" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.1, page no. 179" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def main(): #defining a function \n", + " print \"Hello World!\"\n", + "\n", + "main()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World!\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.2, page no. 180" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def printMessage(): # defining function\n", + " print \"Hello world!\"\n", + "\n", + "printMessage() # calling the function" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello world!\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.3, page no. 181" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "printMessage();\n", + "\n", + "def printMessage():\n", + " print \"Hello world!\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello world!\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.4, page no. 182" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printMessage():\n", + " print \"Hello world!\"\n", + "\n", + "printMessage()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello world!\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.5, page no. 184" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def printMessage():\n", + " times = 0\n", + " times += 1\n", + " print \"This function called \", times, \" times\"\n", + "\n", + "\n", + "\n", + "choice = '1'\n", + "while(choice != 'Q'):\n", + " print \"Enter Q to quit, any other character to continue: \",\n", + " choice = raw_input()\n", + " if (choice == 'Q'):\n", + " print \"Input stopped\"\n", + " else:\n", + " printMessage()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "e\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "e\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Input stopped\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.6, page no. 185" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printMessage():\n", + " times = 0\n", + " times += 1\n", + " print \"This function called \", times, \" times\"\n", + "\n", + "\n", + "choice = '1'\n", + "while(choice != 'Q'):\n", + " print \"Enter Q to quit, any other character to continue: \",\n", + " choice = raw_input()\n", + " if (choice == 'Q'):\n", + " print \"Input stopped\"\n", + " else:\n", + " printMessage()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "w\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Input stopped\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.7, page no. 186" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "times = 0\n", + "def printMessage():\n", + " global times\n", + " times += 1\n", + " print \"This function called \", times, \" times\"\n", + "\n", + "\n", + "choice = '1'\n", + "while(choice != 'Q'):\n", + " print \"Enter Q to quit, any other character to continue: \",\n", + " choice = raw_input()\n", + " if (choice == 'Q'):\n", + " print \"Input stopped\"\n", + " else:\n", + " printMessage()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "w\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "t\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 2 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "u\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 3 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Input stopped\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.8, page no. 189" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "times = 0\n", + "def printMessage():\n", + " global times\n", + " times += 1\n", + " print \"This function called \", times, \" times\"\n", + "\n", + "\n", + "choice = '1'\n", + "while(choice != 'Q'):\n", + " print \"Enter Q to quit, any other character to continue: \",\n", + " choice = raw_input()\n", + " if (choice == 'Q'):\n", + " print \"Input stopped\"\n", + " else:\n", + " printMessage()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "w\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "r\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 2 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "t\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 3 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Input stopped\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.9, page no. 190" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def printMessage():\n", + " print \"You inputted \", str\n", + "\n", + "print \"Enter a string: \",\n", + "str = raw_input()\n", + "printMessage()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a string: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Jeff\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " You inputted Jeff\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.10, page no. 191" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printMessage(s):\n", + " print \"You inputted \", s\n", + "\n", + "print \"Enter a string: \",\n", + "str = raw_input()\n", + "printMessage(str)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a string: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Jeff\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " You inputted Jeff\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.11, page no. 193" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printMessage(firstName, lastName):\n", + " print \"Your name is \", firstName, \" \", lastName\n", + "\n", + "print \"Enter first name:\",\n", + "name1 = raw_input()\n", + "print \"Enter last name:\",\n", + "name2 = raw_input()\n", + "printMessage(name1, name2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter first name:" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Jeff\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter last name:" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Kent\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Your name is Jeff Kent\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.12, page no. 194" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printMessage(thename, theage):\n", + " print \"Your name is \", thename, \" and your age is\", theage\n", + "\n", + "print \"Enter name:\",\n", + "name = raw_input()\n", + "print \"Enter age:\",\n", + "age = int(raw_input())\n", + "printMessage(name, age)\n", + "printMessage(age, name)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter name:" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Jeff\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter age:" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "34\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Your name is Jeff and your age is 34\n", + "Your name is 34 and your age is Jeff\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.13, page no. 195" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def doubleIt(x):\n", + " print \"The number to be doubled is \", x\n", + " x *= 2\n", + " print \"The number doubled in doubleIt is \", x\n", + "\n", + "print \"Enter number: \",\n", + "num = int(raw_input())\n", + "doubleIt(num)\n", + "print \"The number doubled outside the function is \", num," + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "34\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The number to be doubled is 34\n", + "The number doubled in doubleIt is 68\n", + "The number doubled outside the function is 34\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.14, page no. 196" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "li = [0]\n", + "def doubleIt():\n", + " print \"The number to be doubled is \", li[0]\n", + " li[0] *= 2\n", + " print \"The number doubled in doubleIt is \", li[0]\n", + " \n", + "print \"Enter number: \",\n", + "num = int(raw_input())\n", + "li[0] = num\n", + "doubleIt()\n", + "print \"The number doubled outside the function is \", li[0]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The number to be doubled is 5\n", + "The number doubled in doubleIt is 10\n", + "The number doubled outside the function is 10\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.15, page no. 197" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "z = []\n", + "def addNumbers (a, b):\n", + " z.append(a + b)\n", + "\n", + "\n", + "print \"Enter first number: \",\n", + "firstNum = int(raw_input())\n", + "print \"Enter second number: \",\n", + "secondNum = int(raw_input())\n", + "addNumbers(firstNum, secondNum)\n", + "print firstNum, \" + \", secondNum, \" = \", z[0]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter first number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter second number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 3 + 4 = 7\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 9.16, page no. 199" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def addNumbers(x, y):\n", + " return x + y\n", + "\n", + "print \"Enter first number: \",\n", + "firstNum = int(raw_input())\n", + "print \"Enter second number: \",\n", + "secondNum = int(raw_input())\n", + "sum = addNumbers(firstNum, secondNum)\n", + "print firstNum, \" + \", secondNum, \" = \", sum\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter first number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Enter second number: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 4 + 5 = 9\n" + ] + } + ], + "prompt_number": 24 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_Demystified:_A_Self-Teaching_Guide/chapter13.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/chapter13.ipynb index a7e400b9..8c87053f 100755 --- a/C++_Demystified:_A_Self-Teaching_Guide/chapter13.ipynb +++ b/C++_Demystified:_A_Self-Teaching_Guide/chapter13.ipynb @@ -41,17 +41,14 @@ "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'fp' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mif\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfp\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"infile = \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfp\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"0\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'fp' is not defined" + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" ] } ], - "prompt_number": 1 + "prompt_number": 4 }, { "cell_type": "heading", diff --git a/C++_Demystified:_A_Self-Teaching_Guide/chapter5.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/chapter5.ipynb index 7973421f..e0f1a684 100755 --- a/C++_Demystified:_A_Self-Teaching_Guide/chapter5.ipynb +++ b/C++_Demystified:_A_Self-Teaching_Guide/chapter5.ipynb @@ -459,31 +459,8 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "StdinNotImplementedError", - "evalue": "raw_input was called, but this frontend does not support stdin.", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mStdinNotImplementedError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/jovina/TBC/hardik/c++-demystified/\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"L for Leather Seats\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"D for Leather Seats + Chrome Wheels\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mchoice\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mraw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 10\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Extra features purchased\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mchoice\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'D'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m/home/jovina/epd/lib/python2.7/site-packages/IPython/zmq/ipkernel.pyc\u001b[0m in \u001b[0;36m\u001b[1;34m(prompt)\u001b[0m\n\u001b[0;32m 251\u001b[0m \u001b[0mraw_input\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mprompt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m''\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_raw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mprompt\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mident\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparent\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 252\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 253\u001b[1;33m \u001b[0mraw_input\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mprompt\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m''\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_no_raw_input\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 254\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 255\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mpy3compat\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPY3\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m/home/jovina/epd/lib/python2.7/site-packages/IPython/zmq/ipkernel.pyc\u001b[0m in \u001b[0;36m_no_raw_input\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 443\u001b[0m \"\"\"Raise StdinNotImplentedError if active frontend doesn't support\n\u001b[0;32m 444\u001b[0m stdin.\"\"\"\n\u001b[1;32m--> 445\u001b[1;33m raise StdinNotImplementedError(\"raw_input was called, but this \"\n\u001b[0m\u001b[0;32m 446\u001b[0m \"frontend does not support stdin.\") \n\u001b[0;32m 447\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mStdinNotImplementedError\u001b[0m: raw_input was called, but this frontend does not support stdin." - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Choose your car\n", - "S for Standard\n", - "L for Leather Seats\n", - "D for Leather Seats + Chrome Wheels\n" - ] - } - ], - "prompt_number": 1 + "outputs": [], + "prompt_number": "*" }, { "cell_type": "code", diff --git a/C++_Demystified:_A_Self-Teaching_Guide/chapter9.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/chapter9.ipynb index 78228f18..5b5e1ccb 100755 --- a/C++_Demystified:_A_Self-Teaching_Guide/chapter9.ipynb +++ b/C++_Demystified:_A_Self-Teaching_Guide/chapter9.ipynb @@ -157,11 +157,12 @@ "input": [ "\n", "def printMessage():\n", + " times = 0\n", " times += 1\n", " print \"This function called \", times, \" times\"\n", "\n", "\n", - "times = 0\n", + "\n", "choice = '1'\n", "while(choice != 'Q'):\n", " print \"Enter Q to quit, any other character to continue: \",\n", @@ -178,6 +179,22 @@ "output_type": "stream", "stream": "stdout", "text": [ + " Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "e\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", "Enter Q to quit, any other character to continue: " ] }, @@ -190,18 +207,46 @@ ] }, { - "ename": "UnboundLocalError", - "evalue": "local variable 'times' referenced before assignment", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mUnboundLocalError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"Input stopped\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 19\u001b[1;33m \u001b[0mprintMessage\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36mprintMessage\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mprintMessage\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----> 7\u001b[1;33m \u001b[0mtimes\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"This function called \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\" times\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mUnboundLocalError\u001b[0m: local variable 'times' referenced before assignment" + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " This function called 1 times\n", + "Enter Q to quit, any other character to continue: " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Q\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Input stopped\n" ] } ], - "prompt_number": 8 + "prompt_number": 4 }, { "cell_type": "heading", diff --git a/C++_Demystified:_A_Self-Teaching_Guide/students.dat b/C++_Demystified:_A_Self-Teaching_Guide/students.dat new file mode 100644 index 00000000..e69de29b diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch1-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch1-checkpoint.ipynb new file mode 100755 index 00000000..a9c91080 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch1-checkpoint.ipynb @@ -0,0 +1,261 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2af50dca95bb8940069ca1eefad39c58f8f97bbf13a194cd9fff16b4f6521b4f" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter One : Naming" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.1 Page no : 2 \n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "strL = 0 # Not recommended\n", + "stringLength = 0 # Recommended" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 2 Page no : 3\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcFruit:\n", + " def print_(self):\n", + " pass\n", + "\n", + "class EmcApple(EmcFruit):\n", + " def print_(self):\n", + " pass\n", + "\n", + "fp = EmcApple()\n", + "print fp " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "<__main__.EmcApple instance at 0x9d29c8c>\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.3 Page no : 4\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Point:\n", + " def __init__(self,a,b):\n", + " self.x = a\n", + " self.y = b\n", + " def x1(self,a):\n", + " self.x = a\n", + "\n", + "p = Point(0,0) # a point in a 2-dimensional space\n", + "p.x1(1); # set X-coordinate\n", + "print p.x # prints X-coordinate, \"1\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.4 page no : 4\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def check_assign(a,i,t):\n", + " if (i < len(a)):\n", + " a[i] = t;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.5 Page no : 6\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class String:\n", + " pass\n", + "\n", + "class DynamicArray:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.6 page no : 6\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = 'aaa' \n", + "s1 = 'xyz'\n", + "s = 'abc' # Emc::String s;\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.8 page no : 7\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#s1 = EmcString() # Belongs to the Emc Class Library\n", + "#s2 = OtherString() # Belongs to the Other Class Library" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.9 Page no : 8\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#import RWCstring #include \"RWCstring.h\" /* Recommended */\n", + "#from rw import cstring #include \"rw/cstring.h\" /* Sometimes needed */" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.10 page no : 9\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "i__j = 11;\n", + "_K = 22;\n", + "_m = 33;\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch10-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch10-checkpoint.ipynb new file mode 100755 index 00000000..6292c70e --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch10-checkpoint.ipynb @@ -0,0 +1,490 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:70f9ab632bffbd9fecc3bdcee575cac266cb09d4df74fddec4e595d028f134df" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter Ten : Object-oriented programming

" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 10.1 page no :105" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "s = \"hello\" # length() == 5\n", + "print s\n", + "print len(s)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello\n", + "5" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.2 page no : 106" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s = \"Hello\"\n", + "\n", + "s = s.lower()\n", + "print s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 10.3 page no :107" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " \n", + " def insert(self,t):\n", + " pass\n", + " \n", + " def operator(self, coll):\n", + " pass\n", + "\n", + "class EmcArrayCollection(EmcCollection):\n", + " initialSize = 10\n", + "\n", + " def __init__(self,maxsize):\n", + " pass\n", + "\n", + "\"\"\"\n", + "class InvalidCollectionType(EmcException):\n", + " \n", + " def __init__(self,i):\n", + " pass\n", + " \"\"\"\n", + "\n", + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def create(self,type):\n", + " pass\n", + "\n", + " def createArray(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 10.4 page no :109" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def create(self,type):\n", + " pass\n", + "\n", + " def createArray(self):\n", + " pass\n", + "\n", + "factory = EmcCollectionFactory()\n", + "collection = factory.create(\"Array\")\n", + "collection.insert(42); # EmcArrayCollection::insert() is called\n", + "print collection" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "None\n" + ] + } + ], + "prompt_number": 32 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 10.5 page no : 111" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcCollection:\n", + " def __del__(self):\n", + " pass\n", + "\n", + "class EmcArrayCollection( EmcCollection):\n", + " def __del__(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 10.6 page no :112" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcLogged:\n", + " def writeClassName(self,o):\n", + " pass\n", + "\n", + " def writeValue(self,o):\n", + " pass\n", + "\n", + " def logMessage(self,message):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + "class EmcLoggedCollection(EmcCollection):\n", + "\n", + " def writeValue(self,o):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.7 Page no : 117" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "\n", + "class EmcIntStack:\n", + " def empty(self):\n", + " pass\n", + "\n", + " def full(self):\n", + " pass\n", + " \n", + " def top(self):\n", + " pass\n", + " \n", + " def push(self,i):\n", + " pass\n", + " \n", + " def pop(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.8 Page no : 117" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def makeString(stack):\n", + " returnValue = ''\n", + " copy = stack\n", + " while (not copy.empty()):\n", + " # loop condition makes precondition valid\n", + " print copy.pop() # Precondition: ! copy.empty()\n", + " returnValue += copy.pop\n", + "\n", + " return returnValue;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.9 page no : 118" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcString:\n", + " def cStr(self):\n", + " pass\n", + " # cStr() returns 0-terminated string\n", + "\n", + " def length(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.10 page no : 119" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def insert(self,T):\n", + " pass\n", + "\n", + " def clear(self):\n", + " pass\n", + "\n", + " def remove(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.11 page no : 120" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def create(self,type):\n", + " pass\n", + "\n", + " def createArray(self):\n", + " pass\n", + " \n", + "factrory = EmcCollectionFactory()\n", + "collection = factory.create(\"Array\");\n", + "if (not collection.isFull()):\n", + " collection.insert(42);" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 36 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.12 page no : 121" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def insertObject(c,element):\n", + " \n", + " if (not c.isFull()):\n", + " c.insert(element)\n", + " return True\n", + " return False" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.13 Page no : 121" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def insert(T):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.14 page no : 123" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 10.15 page no : 124" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcCollection:\n", + " def templateRequirements(self):\n", + " pass\n", + "\n", + " def templateRequirements(self):\n", + " \n", + " t1 = T1()\n", + " \n", + " t2 =t1\n", + "\n", + " t2 = t1;\n", + " # Assignable\n", + " b = (t2 == t1); # EqualityComparable" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch12-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch12-checkpoint.ipynb new file mode 100755 index 00000000..c8f2cfb1 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch12-checkpoint.ipynb @@ -0,0 +1,355 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:3fda869111a137bc83ae4b79f3c57ac84f247031c3e08ac7d6dfb9bb168b3105" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter Twelve : Error handling" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.1 page no : 135" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import socket\n", + "import sys\n", + "import os\n", + "sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM,0)\n", + "\n", + "if(sock < 0):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.2 page no : 136" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def operator(self,n):\n", + " pass\n", + "\n", + "class EmcSystemException( EmcException):\n", + " def __init__(self,m):\n", + " pass\n", + " \n", + " def emcSocket(self,family,t,protocol):\n", + " # create socket\n", + " socketfd = socket(family, t, protocol);\n", + " if (socketfd < 0): # check status value\n", + " raise EmcSystemException(\"emcSocket\");\n", + " return socketfd;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.3 page no : 139" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def __init__(self,cp):\n", + " self.lengthM = len(cp)\n", + " self.cpM = cp" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.5 page no : 141" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcLog:\n", + " def __init__(self,filename):\n", + " pass\n", + "\n", + " def message(self,EmcString):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " if uncaught_exception():\n", + " self.flush()\n", + " \n", + " def flush(self):\n", + " if ( not uncaught_exception()):\n", + " raise EmcSystemException(\"EmcLog::flush()\")" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.6 page no : 142" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def __init__(self,m):\n", + " maxSizeM = 100\n", + " actualLength = len(m);\n", + " self.lengthM = min(maxSizeM,actualLength);\n", + " self.messageM = message" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.7" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)\n", + "\n", + "\n", + "def g(i):\n", + " raise Exception(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.8 page no : 146" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)\n", + "\n", + "def g(i):\n", + " raise Exception(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.9 page no :146" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.10 page no : 148" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcStack:\n", + " defaultSizeM = 100\n", + " def __init__(self,size = 100):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def operator(self,s):\n", + " pass\n", + "\n", + " def empty(self):\n", + " pass\n", + " \n", + " def top(self):\n", + " pass\n", + "\n", + " def push(self,i):\n", + " pass\n", + " \n", + " def pop(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.12 page no : 151" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def __init__(self,m):\n", + " pass\n", + " \n", + " def operator(self,o,EmcException):\n", + " pass\n", + "\n", + " def printOn(self,o): \n", + " print self.messageM;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.13 page no : 153" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "try:\n", + " socketfd = emcSocket(AF_UNIX, SOCK_STREAM, 0);\n", + "except Exception,e:\n", + " print e" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 'emcSocket' is not defined" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 12.14 page no : 155" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def at(s,pos):\n", + " if (pos > len(s)):\n", + " raise Exception;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch13-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch13-checkpoint.ipynb new file mode 100755 index 00000000..8bf2f3f0 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch13-checkpoint.ipynb @@ -0,0 +1,350 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:121cbe714f8e854e8d9ce1fe8dcdc370535cc7140b2f83bdae09063602e644f9" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter Thirteen : Parts of C++ to avoid" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.1 page no : 159" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s = 'abc' #raw_input()\n", + "print s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "abc" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.2 page no : 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class DangerousString:\n", + " def __init__(self,cp):\n", + " pass\n", + " \n", + " def char(self):\n", + " pass\n", + "\n", + "hello = \"Hello World!\";\n", + "print hello # Works perfectly\n", + "print \"%s\"%hello" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World!\n", + "Hello World!" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.3 page no : 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcString:\n", + " def __init__(self,cp):\n", + " pass\n", + "\n", + "\n", + "s = \"Hello World!\";\n", + "print s " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World!" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.4 page no :161" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "SIZE = 1024;\n", + "print SIZE" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1024" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.5 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class X:\n", + " class Color:\n", + " green = 1\n", + " yellow = 2\n", + " red = 3" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.6 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class X:\n", + " maxBuf = 1024\n", + " class Color:\n", + " green = 1\n", + " yellow = 2\n", + " red = 3" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.7 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def SQUARE(x):\n", + " return x*x\n", + "\n", + "i = SQUARE(3 + 4); \n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "49" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.8 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def square(x):\n", + " return x * x;\n", + "c = 2;\n", + "d = square(c)\n", + "print d" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.9 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "def SQUARE(x):\n", + " return x*x\n", + "i = SQUARE(\"hello\");\n", + "print i\n", + "\"\"\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 10, + "text": [ + "'\\ndef SQUARE(x):\\n return x*x\\ni = SQUARE(\"hello\");\\nprint i\\n'" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.10 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#define Velocity int\n", + "#typedef int Velocity;\n", + "# Not recommended" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 11, + "text": [ + "'\\nEXAMPLE 13.10 page no : 163\\nHow to define synonyms for a type\\nNote : Python doesnot have synonyms for type as we do not have to explicitely \\ndeclare variables.\\n'" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 13.11 page no : 164" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def printFruits(fruits,size):\n", + " for i in range(size):\n", + " print fruits[i] " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch15-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch15-checkpoint.ipynb new file mode 100755 index 00000000..62a8a475 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch15-checkpoint.ipynb @@ -0,0 +1,611 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:24f5f3b754e3fd6e8afab7bcb99e41e817ec5bce9faae498ba9fb75dd53f93ff" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Chapter Fifteen : Portability" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.1 page no : 172" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "c = -100;\n", + "if (c < 0):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.2 page no : 173" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class BasicAttrType:\n", + " counterGauge = 0x1000\n", + " counterPeg = 0x2000\n", + " conterAcc = 0x3000\n", + " \n", + "\n", + "\n", + "t = BasicAttrType.counterGauge\n", + "print t" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4096" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.3 page no : 173" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = ''\n", + "print a" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 15.5 page no : 174" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "result = 1234 * 567\n", + "print result" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "699678" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Example 15.6 page no : 175" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "import math # python has only one way to importing file.\n", + "from math import *" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

exmaple 15.7 page no : 176" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + " \n", + "# import inc.MyFile\n", + "# import inc.MyFile\n", + "\n", + "# import gui.xinterface" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 6, + "text": [ + "'\\nexmaple 15.7 page no : 176\\nDirectory names in include directives\\nNote : python has . operator to import a file from directory\\n'" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.8 page no : 176" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "import math\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.9 page no : 178" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class PersonRecord:\n", + " ageM = ''\n", + " phoneNumberM = 0\n", + " nameM = ''" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.10 page no : 178" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def stepAndConvert(a,n):\n", + " b = a + str(n) # step n chars ahead\n", + " return b # NO: Dangerous cast of const char* to int*\n", + "\n", + "\n", + "data = \"abcdefghijklmnop\"\n", + "anInt = 3;\n", + "i = stepAndConvert(data, anInt)\n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "abcdefghijklmnop3" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.11 page no : 179" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "INT_MIN = -2147483648\n", + "INT_MAX = 2147483647\n", + "UINT_MAX = 4294967295\n", + "i = 42\n", + "ui = 2222222242;\n", + "j = i - ui;\n", + "print j" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2222222200" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.12 page no : 180" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "zero = 0;\n", + "one = 1;\n", + "minusOne = zero - one;\n", + "print minusOne\n", + "result = one + minusOne;\n", + "print result" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n", + "0" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.13 page no : 180" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#pid1 = fork(); # NO: should use pid_t\n", + "\n", + "#pid2 = fork();" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.14 page no : 181" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "famousClimber = \"Edmund Hillary\"; # Uses Emc as prefix\n", + "print famousClimber" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Edmund Hillary" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.15 page no : 183" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcArray:\n", + " def __init__(self,size):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.16 page no : 183" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "\n", + "false = 0;\n", + "true = 1;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.17 page no : 184" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\"\"\"\n", + "i = 0;\n", + "for i in range(last()):\n", + " pass\n", + "\n", + "for i in range(first()):\n", + " pass\n", + " \"\"\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 5, + "text": [ + "'\\ni = 0;\\nfor i in range(last()):\\n pass\\n\\nfor i in range(first()):\\n pass\\n '" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.18 page no : 185" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def emcMax(a, b):\n", + " if a>b:\n", + " return a\n", + " return b\n", + "\n", + "def foo(i,j):\n", + " m = emcMax(i, j); # usage of emcMax\n", + "\n", + "q = 0 # usage of class EmcQueue and\n", + "s = 0 # EmcQueue:s default constructor" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.19 page no : 186" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcQueue:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.20 page no : 187" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class DangerousString:\n", + " def __init__(self,cp):\n", + " pass\n", + "\n", + " def char(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

example 15.22 page no : 189" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def main(self):\n", + " return 0" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.23" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "func(f1(), f2(), f3()) # f1 may be evaluated before f2 and f3,\n", + "# but don't depend on it!" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

EXAMPLE 15.24 page no : 189" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = [0,0,0]\n", + "i = 0\n", + "a[i] = i;\n", + "i += 1\n", + "print i \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch2-checkpoint.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch2-checkpoint.ipynb new file mode 100755 index 00000000..a2d1bd52 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/.ipynb_checkpoints/ch2-checkpoint.ipynb @@ -0,0 +1,249 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:025b4c65298f5bb6d48b99d717b6d0fce940f5a97ad7eb75ea5897c4c9595891" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter : Two : Organizing the code" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.1 Page no : 12\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#import EmcArray # EmcArray.py\n", + "#import iostream # The rest of the EmcArray.cc file " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.2 page no : 13\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "\n", + "class X :\n", + " def __init__(self):\n", + " pass #self.aM = A()\n", + " \n", + " def returnA(self):\n", + " pass #return self.aM\n", + " \n", + " def withAParameter(self,a):\n", + " pass #self.aM = a" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.3 page no :14\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Y :\n", + " def __init__(self):\n", + " pass #self.bM = B()\n", + " \n", + " def returnBPtr(self):\n", + " pass #return self.aM\n", + " \n", + " def withAParameter(self,b):\n", + " pass #self.bM = a\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.4 page no : 15\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def module_exists(module_name):\n", + " try:\n", + " __import__(module_name)\n", + " except ImportError:\n", + " return False\n", + " else:\n", + " return True" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.5 page no : 15\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def cStr(cpM):\n", + " return cpM\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.6 page no : 17\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "def max_(x,y):\n", + " if x > y:\n", + " return x\n", + " return y\n", + "\n", + "def function(i,j):\n", + " m = max_(i,j) # must instantiate max(int,int)\n", + " print m\n", + "\n", + "function(5,10) \n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.7 page no : 17\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcQueue:\n", + " def __init__(self):\n", + " pass\n", + " \n", + " def insert(self,t):\n", + " pass\n", + "\n", + "q = EmcQueue()\n", + "q.insert(42);" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.8 page no : 18\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcQueue:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb index 834bacf2..a9c91080 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb @@ -194,25 +194,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", - "s1 = EmcString() # Belongs to the Emc Class Library\n", - "s2 = OtherString() # Belongs to the Other Class Library" + "#s1 = EmcString() # Belongs to the Emc Class Library\n", + "#s2 = OtherString() # Belongs to the Other Class Library" ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'EmcString' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mthis\u001b[0m \u001b[0mwill\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mfile\u001b[0m \u001b[0mdoesn\u001b[0m\u001b[0;31m'\u001b[0m\u001b[0mt\u001b[0m \u001b[0mhave\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mEmcString\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mOtherString\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0ms1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mEmcString\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Belongs to the Emc Class Library\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[0ms2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mOtherString\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Belongs to the Other Class Library\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'EmcString' is not defined" - ] - } - ], - "prompt_number": 7 + "outputs": [], + "prompt_number": 4 }, { "cell_type": "heading", @@ -227,24 +215,13 @@ "collapsed": false, "input": [ "\n", - "import RWCstring #include \"RWCstring.h\" /* Recommended */\n", - "from rw import cstring #include \"rw/cstring.h\" /* Sometimes needed */" + "#import RWCstring #include \"RWCstring.h\" /* Recommended */\n", + "#from rw import cstring #include \"rw/cstring.h\" /* Sometimes needed */" ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "ImportError", - "evalue": "No module named RWCstring", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mthis\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mwe\u001b[0m \u001b[0mdont\u001b[0m \u001b[0mhave\u001b[0m \u001b[0mpackages\u001b[0m \u001b[0mwritten\u001b[0m \u001b[0mhere\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m '''\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mRWCstring\u001b[0m \u001b[1;31m#include \"RWCstring.h\" /* Recommended */\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mrw\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mcstring\u001b[0m \u001b[1;31m#include \"rw/cstring.h\" /* Sometimes needed */\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mImportError\u001b[0m: No module named RWCstring" - ] - } - ], - "prompt_number": 8 + "outputs": [], + "prompt_number": 5 }, { "cell_type": "heading", diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb index 52781089..6292c70e 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb @@ -103,11 +103,12 @@ " def __init__(self,maxsize):\n", " pass\n", "\n", - "\n", + "\"\"\"\n", "class InvalidCollectionType(EmcException):\n", " \n", " def __init__(self,i):\n", " pass\n", + " \"\"\"\n", "\n", "class EmcCollectionFactory:\n", " def __init__(self):\n", @@ -121,19 +122,8 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'EmcException' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0;32mclass\u001b[0m \u001b[0mInvalidCollectionType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mEmcException\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 25\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'EmcException' is not defined" - ] - } - ], - "prompt_number": 3 + "outputs": [], + "prompt_number": 2 }, { "cell_type": "markdown", @@ -146,10 +136,18 @@ "cell_type": "code", "collapsed": false, "input": [ + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def create(self,type):\n", + " pass\n", "\n", + " def createArray(self):\n", + " pass\n", "\n", "factory = EmcCollectionFactory()\n", - "collection = factory.create(ArrayId)\n", + "collection = factory.create(\"Array\")\n", "collection.insert(42); # EmcArrayCollection::insert() is called\n", "print collection" ], @@ -157,17 +155,14 @@ "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'EmcCollectionFactory' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mfactory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mEmcCollectionFactory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mcollection\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mArrayId\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minsert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# EmcArrayCollection::insert() is called\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'EmcCollectionFactory' is not defined" + "output_type": "stream", + "stream": "stdout", + "text": [ + "None\n" ] } ], - "prompt_number": 4 + "prompt_number": 32 }, { "cell_type": "markdown", @@ -364,27 +359,25 @@ "collapsed": false, "input": [ "\n", + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", "\n", + " def create(self,type):\n", + " pass\n", + "\n", + " def createArray(self):\n", + " pass\n", + " \n", "factrory = EmcCollectionFactory()\n", - "collection = factory.create(ArrayId);\n", + "collection = factory.create(\"Array\");\n", "if (not collection.isFull()):\n", " collection.insert(42);" ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'EmcCollectionFactory' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mfactrory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mEmcCollectionFactory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mcollection\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mArrayId\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mnot\u001b[0m \u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misFull\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'EmcCollectionFactory' is not defined" - ] - } - ], - "prompt_number": 11 + "outputs": [], + "prompt_number": 36 }, { "cell_type": "markdown", diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb index a4d7907e..c8f2cfb1 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb @@ -26,26 +26,18 @@ "cell_type": "code", "collapsed": false, "input": [ + "import socket\n", + "import sys\n", + "import os\n", + "sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM,0)\n", "\n", - "socketfd = socket(AF_UNIX, SOCK_STREAM, 0);\n", - "if(socketfd < 0):\n", + "if(sock < 0):\n", " pass" ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'socket' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m//\u001b[0m \u001b[0mcreate\u001b[0m \u001b[0msocket\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m '''\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0msocketfd\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msocket\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAF_UNIX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSOCK_STREAM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0;32mif\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msocketfd\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'socket' is not defined" - ] - } - ], - "prompt_number": 1 + "outputs": [], + "prompt_number": 7 }, { "cell_type": "markdown", diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb index a23bdf0e..8bf2f3f0 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb @@ -262,24 +262,22 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", + "\"\"\"\n", "def SQUARE(x):\n", " return x*x\n", "i = SQUARE(\"hello\");\n", - "print i" + "print i\n", + "\"\"\"" ], "language": "python", "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "can't multiply sequence by non-int of type 'str'", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36mSQUARE\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'str'" + "metadata": {}, + "output_type": "pyout", + "prompt_number": 10, + "text": [ + "'\\ndef SQUARE(x):\\n return x*x\\ni = SQUARE(\"hello\");\\nprint i\\n'" ] } ], diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb index 32ad5666..62a8a475 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb @@ -336,25 +336,14 @@ "collapsed": false, "input": [ "\n", - "pid1 = fork(); # NO: should use pid_t\n", + "#pid1 = fork(); # NO: should use pid_t\n", "\n", - "pid2 = fork();" + "#pid2 = fork();" ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'fork' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0mIt\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mshoot\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mdefined\u001b[0m \u001b[0mhere\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mpid1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# NO: should use pid_t\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mpid2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'fork' is not defined" - ] - } - ], - "prompt_number": 12 + "outputs": [], + "prompt_number": 2 }, { "cell_type": "markdown", @@ -439,29 +428,28 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", + "\"\"\"\n", "i = 0;\n", "for i in range(last()):\n", " pass\n", "\n", "for i in range(first()):\n", - " pass" + " pass\n", + " \"\"\"" ], "language": "python", "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'last' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/home/jay/\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlast\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'last' is not defined" + "metadata": {}, + "output_type": "pyout", + "prompt_number": 5, + "text": [ + "'\\ni = 0;\\nfor i in range(last()):\\n pass\\n\\nfor i in range(first()):\\n pass\\n '" ] } ], - "prompt_number": 16 + "prompt_number": 5 }, { "cell_type": "markdown", diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb index 8660012f..a2d1bd52 100755 --- a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb @@ -29,24 +29,13 @@ "collapsed": false, "input": [ "\n", - "import EmcArray # EmcArray.py\n", - "import iostream # The rest of the EmcArray.cc file " + "#import EmcArray # EmcArray.py\n", + "#import iostream # The rest of the EmcArray.cc file " ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "ImportError", - "evalue": "No module named EmcArray", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mwe\u001b[0m \u001b[0mdont\u001b[0m \u001b[0mhave\u001b[0m \u001b[0mEmcArray\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0miostream\u001b[0m \u001b[0mpackages\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mEmcArray\u001b[0m \u001b[1;31m# EmcArray.py\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0miostream\u001b[0m \u001b[1;31m# The rest of the EmcArray.cc file\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mImportError\u001b[0m: No module named EmcArray" - ] - } - ], - "prompt_number": 1 + "outputs": [], + "prompt_number": 2 }, { "cell_type": "heading", diff --git a/Engineering_Physics_Vijaya/.ipynb_checkpoints/chapter2_2-checkpoint.ipynb b/Engineering_Physics_Vijaya/.ipynb_checkpoints/chapter2_2-checkpoint.ipynb new file mode 100755 index 00000000..2ff5590c --- /dev/null +++ b/Engineering_Physics_Vijaya/.ipynb_checkpoints/chapter2_2-checkpoint.ipynb @@ -0,0 +1,814 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:04561aafd347865fa8c83acfb9b60eb84db275f85862655b442f546023cadd1e" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Electron Theory of Metals" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.1, Page number 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#import module\n", + "import math\n", + "\n", + "#Calculation\n", + "# given that E-Ef = kT\n", + "# fermi function FE = 1/(1+exp((E-Ef)/kT)\n", + "# therefore FE = 1/(1+exp(kT/kT));\n", + "# FE = 1/(1+exp(1))\n", + "FE=1/(1+math.exp(1));\n", + "FE=math.ceil(FE*10**2)/10**2; #rounding off to 2 decimals\n", + "\n", + "#Result\n", + "print(\"fermi function is\",FE);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('fermi function is', 0.27)\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.2, Page number 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "\n", + "#Calculation\n", + "# given that E-Ef = kT\n", + "# fermi function FE = 1/(1+exp((E-Ef)/kT)\n", + "# therefore FE = 1/(1+exp(kT/kT));\n", + "# FE = 1/(1+exp(1))\n", + "FE=1/(1+math.exp(1));\n", + "FE=math.ceil(FE*10**3)/10**3; #rounding off to 3 decimals\n", + "\n", + "#Result\n", + "print(\"fermi function is\",FE);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('fermi function is', 0.269)\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.3, Page number 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "FE=10/100; #fermi function is 10%\n", + "Ef=5.5; #fermi energy of silver in eV\n", + "k=1.38*10**-23;\n", + "\n", + "#Calculation\n", + "E=Ef+(Ef/100);\n", + "#FE=1/(1+math.exp((E-Ef)/(k*T)))\n", + "#therefore 1/FE = 1+math.exp((E-Ef)/(k*T))\n", + "#therefore (1/FE)-1 = math.exp((E-Ef)/(k*T))\n", + "#therefore log((1/FE)-1) = (E-Ef)/(k*T)\n", + "#therefore T = (E-Ef)/(k*math.log((1/FE)-1))\n", + "#let X=E-Ef; \n", + "X=E-Ef; #energy in eV\n", + "X=X*1.6*10**-19; #energy in J\n", + "T = (X/(k*math.log((1/FE)-1)));\n", + "T=math.ceil(T*10**2)/10**2; #rounding off to 2 decimals\n", + "\n", + "#Result\n", + "print(\"temperature in K is\",T);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('temperature in K is', 290.23)\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.4, Page number 70 **************************************" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "#let X=E-Ef\n", + "X=0.5; #E-Ef=0.5 in eV\n", + "\n", + "#Calculation\n", + "X=X*1.6*10**-19; #X in J\n", + "FE=1/100; #fermi function is 1% \n", + "k=1.38*10**-23;\n", + "#FE=1/(1+exp(X/(k*T)))\n", + "#therefore 1/FE = 1+math.exp(X/(k*T))\n", + "#therefore (1/FE)-1 = math.exp(X/(k*T))\n", + "#therefore log((1/FE)-1) = X/(k*T)\n", + "#but log(x) = 2.303*math.log10(x)\n", + "#therefore T = X/(k*math.log((1/FE)-1))\n", + "#but log(x)=2.303*math.log10(x)\n", + "#therefore T = X/(k*2.303*math.log10((1/FE)-1))\n", + "T = X/(k*2.303*math.log10((1/FE)-1));\n", + "\n", + "#Result\n", + "print(\"temperature in K is\",T);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('temperature in K is', 1261.3505710887953)\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.5, Page number 71 *******" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "rho_s=10.5*10**3; #density in kg/m^3\n", + "NA=6.02*10**26; #avagadro number per kmol\n", + "MA=107.9; \n", + "\n", + "#Calculation\n", + "n=(rho_s*NA)/MA;\n", + "sigma=6.8*10**7;\n", + "e=1.6*10**-19; #charge in coulomb\n", + "mew=sigma/(n*e);\n", + "mew=math.ceil(mew*10**6)/10**6; #rounding off to 6 decimals\n", + "\n", + "#Result\n", + "print(\"density of electrons is\",n);\n", + "print(\"mobility of electrons in silver in m^2/Vs is\",mew);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('density of electrons is', 5.85820203892493e+28)\n", + "('mobility of electrons in silver in m^2/Vs is', 0.007255)\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.6, Page number 71 ***" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "d=8.92*10**3; #density in kg/m^3\n", + "rho=1.73*10**-8; #resistivity in ohm-m\n", + "m=9.1*10**-31; #mass in kg\n", + "w=63.5; #atomic weight\n", + "e=1.6*10**-19; #charge in coulomb\n", + "A=6.02*10**26; #avagadro number\n", + "\n", + "#Calculation\n", + "n=(d*A)/w;\n", + "mew=1/(rho*n*e);\n", + "tow=m/(n*(e**2)*rho);\n", + "mew=math.ceil(mew*10**6)/10**6; #rounding off to 6 decimals\n", + "\n", + "#Result\n", + "print(\"mobility of electrons in Copper in m/Vs is\",mew);\n", + "print(\"average time of collision of electrons in copper in sec is\",tow);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('mobility of electrons in Copper in m/Vs is', 0.004273)\n", + "('average time of collision of electrons in copper in sec is', 2.4297841992299697e-14)\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.7, Page number 72" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "rho=1.54*10**-8; #resistivity in ohm-m\n", + "n=5.8*10**28; #electron/m^3\n", + "m=9.108*10**-31; #mass in kg\n", + "e=1.602*10**-19; #charge in coulomb\n", + "\n", + "#Calculation\n", + "tow=m/(n*(e**2)*rho);\n", + "\n", + "#Result\n", + "print(\"relaxation time of conduction electrons in sec is\",tow);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('relaxation time of conduction electrons in sec is', 3.973281032516849e-14)\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.8, Page number 73" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "FE=10/100; #fermi function is 10%\n", + "Ef=5.5; #fermi energy of silver in eV\n", + "k=1.38*10**-23;\n", + "\n", + "#Calculation\n", + "E=Ef+(Ef/100);\n", + "#FE=1/(1+math.exp((E-Ef)/(k*T)))\n", + "#therefore 1/FE = 1+math.exp((E-Ef)/(k*T))\n", + "#therefore (1/FE)-1 = math.exp((E-Ef)/(k*T))\n", + "#therefore log((1/FE)-1) = (E-Ef)/(k*T)\n", + "#therefore T = (E-Ef)/(k*math.log((1/FE)-1))\n", + "#let X=E-Ef; \n", + "X=E-Ef; #energy in eV\n", + "X=X*1.6*10**-19; #energy in J\n", + "T = (X/(k*math.log((1/FE)-1)));\n", + "T=math.ceil(T*10**2)/10**2; #rounding off to 2 decimals\n", + "\n", + "#Result\n", + "print(\"temperature in K is\",T);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('temperature in K is', 290.23)\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.9, Page number 73" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "\n", + "#Calculation\n", + "# given that E-Ef = kT\n", + "# fermi function FpE = 1/(1+exp((E-Ef)/kT)\n", + "# therefore FpE = 1/(1+exp(kT/kT));\n", + "# FpE = 1/(1+exp(1))\n", + "FpE=1/(1+math.exp(1));\n", + "FpE=math.ceil(FpE*10**2)/10**2; #rounding off to 2 decimals\n", + "\n", + "#Result\n", + "print(\"fermi function is\",FpE);\n", + "#the presence of electron at that energy level is not certain" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('fermi function is', 0.27)\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.10, Page number 74 ****************************" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "m=9.1*10**-31; #mass in kg\n", + "h=6.626*10**-34;\n", + "A=(8*m)**(3/2);\n", + "\n", + "#Calculation\n", + "B=math.pi/(2*h**3);\n", + "EfeV=3.10; #fermi energy in eV\n", + "Ef=EfeV*1.6*10**-19; #fermi energy in J\n", + "EFeV=EfeV+0.02; #energy after interval in eV\n", + "EF=EFeV*1.6*10**-19; #energy after interval in J\n", + "def f(E):\n", + " Q=A*B*math.sqrt(E)\n", + " \n", + "I=(Ef,EF,f)\n", + "\n", + "#Result\n", + "print(\"number of energy states per unit volume is\",I);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('number of energy states per unit volume is', (4.960000000000001e-19, 4.992000000000001e-19, ))\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.11, Page number 74" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "T=300; #temperature in K\n", + "n=8.5*10**28; #density per m^3\n", + "rho=1.69*10**-8; #resistivity in ohm/m^3\n", + "me=9.11*10**-31; #mass of electron in kg\n", + "e=1.6*10**-19; #charge in coulomb\n", + "KB=1.38*10**-23; #boltzmann constant in J/k\n", + "\n", + "#Calculation\n", + "lamda=math.sqrt(3*KB*me*T)/(n*(e**2)*rho);\n", + "\n", + "#Result\n", + "print(\"mean free path of electron in m is\",lamda);\n", + "\n", + "#answer given in the book is wrong" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('mean free path of electron in m is', 2.892506814374228e-09)\n" + ] + } + ], + "prompt_number": 27 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.12, Page number 75" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "rho=1.43*10**-8; #resistivity in ohm-m\n", + "n=6.5*10**28; #electron/m^3\n", + "m=9.11*10**-34; #mass in kg\n", + "e=1.6*10**-19; #charge in coulomb\n", + "\n", + "#Calculation\n", + "tow=m/(n*(e**2)*rho);\n", + "\n", + "#Result\n", + "print(\"relaxation time of conduction electrons in sec is\",tow);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('relaxation time of conduction electrons in sec is', 3.8285032275416887e-17)\n" + ] + } + ], + "prompt_number": 28 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.13, Page number 75 ******" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "d=8.92*10**3; #density in kg/m^3\n", + "rho=1.73*10**-8; #resistivity in ohm-m\n", + "m=9.1*10**-31; #mass in kg\n", + "M=63.5; #atomic weight\n", + "e=1.6*10**-19; #charge in coulomb\n", + "A=6.02*10**26; #avagadro number\n", + "\n", + "#Calculation\n", + "n=(d*A)/M;\n", + "mew=1/(rho*n*e);\n", + "tow=m/(n*(e**2)*rho);\n", + "mew=math.ceil(mew*10**6)/10**6; #rounding off to 6 decimals\n", + "\n", + "#Result\n", + "print(\"mobility of electrons in Copper in m/Vs is\",mew);\n", + "print(\"average time of collision of electrons in copper in sec is\",tow);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('mobility of electrons in Copper in m/Vs is', 0.004273)\n", + "('average time of collision of electrons in copper in sec is', 2.4297841992299697e-14)\n" + ] + } + ], + "prompt_number": 31 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.14, Page number 76" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "MH=1.008*2*1.67*10**-27; #mass in kg\n", + "T=30; #temperature in C\n", + "\n", + "#Calculation\n", + "T=T+273; #temperature in K\n", + "KB=1.38*10**-23; #boltzmann constant in J/k\n", + "KE=(3/2)*KB*T; #kinetic energy in J\n", + "KEeV=KE*6.24*10**18; #kinetic energy in eV\n", + "cbar=math.sqrt((3*KB*T)/MH);\n", + "\n", + "#Result\n", + "print(\"average kinetic energy in J is\",KE);\n", + "print(\"average kinetic energy in eV is\",KEeV);\n", + "print(\"velocity of molecules in m/s is\",cbar);\n", + "\n", + "#answers for average kinetic energy in eV and velocity of electrons given in the book are wrong" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('average kinetic energy in J is', 6.2720999999999986e-21)\n", + "('average kinetic energy in eV is', 0.039137903999999994)\n", + "('velocity of molecules in m/s is', 1930.269663853336)\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.15, Page number 77 ****" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "Ee=10; #electron kinetic energy in eV\n", + "Ep=10; #proton kinetic energy in eV\n", + "me=9.1*10**-31; #mass of electron in kg\n", + "mp=1.67*10**-27; #mass of proton in kg\n", + "\n", + "#Calculation\n", + "EeeV=Ee*1.6*10**-19; #electron kinetic energy in J\n", + "EpeV=Ep*1.6*10**-19; #proton kinetic energy in J\n", + "cebar=math.sqrt((2*EeeV)/me);\n", + "cpbar=math.sqrt((2*EpeV)/mp);\n", + "\n", + "#Result\n", + "print(\"velocity of electron in m/s is\",cebar);\n", + "print(\"velocity of proton in m/s is\",cpbar);\n", + "\n", + "#answers given in the book are wrong" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('velocity of electron in m/s is', 1875228.9237539817)\n", + "('velocity of proton in m/s is', 43774.05241316662)\n" + ] + } + ], + "prompt_number": 35 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.16, Page number 77" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "A=10; #area of cross section in mm^2\n", + "A=A*10**-6; #area of cross section in m^2\n", + "i=100; #current in amp\n", + "n=8.5*10**28; #number of electrons per mm^3\n", + "e=1.6*10**-19; #electron charge in coulumb\n", + "\n", + "#Calculation\n", + "vd=1/(n*A*e);\n", + "\n", + "#Result\n", + "print(\"drift velocity in m/s is\",vd);\n", + "\n", + "#answer given in the book is wrong" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('drift velocity in m/s is', 7.3529411764705884e-06)\n" + ] + } + ], + "prompt_number": 36 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example number 2.17, Page number 78" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "#import module\n", + "import math\n", + "from __future__ import division\n", + "\n", + "#Variable decleration\n", + "tow=3*10**-14; #relaxation time in sec\n", + "n=8*10**28; #density of electrons per m^3\n", + "KB=1.38*10**-23; #boltzmann constant in J/k\n", + "T=0; #temperature in C\n", + "\n", + "#Calculation\n", + "T=T+273; #temperature in K\n", + "m=9.1*10**-31; #mass of electron in kg\n", + "sigma_T=((3*n*tow*(KB**2)*T)/(2*m));\n", + "sigma_T=math.ceil(sigma_T*10**2)/10**2; #rounding off to 2 decimals\n", + "\n", + "#Result\n", + "print(\"thermal conductivity of copper in ohm-1 is\",sigma_T);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "('thermal conductivity of copper in ohm-1 is', 205.68)\n" + ] + } + ], + "prompt_number": 38 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Engineering_Physics_Vijaya/chapter2_2.ipynb b/Engineering_Physics_Vijaya/chapter2_2.ipynb index a118db3c..2ff5590c 100755 --- a/Engineering_Physics_Vijaya/chapter2_2.ipynb +++ b/Engineering_Physics_Vijaya/chapter2_2.ipynb @@ -456,8 +456,10 @@ "Ef=EfeV*1.6*10**-19; #fermi energy in J\n", "EFeV=EfeV+0.02; #energy after interval in eV\n", "EF=EFeV*1.6*10**-19; #energy after interval in J\n", - "function Q=f(E),Q=A*B*math.sqrt(E),endfunction\n", - "I=intg(Ef,EF,f)\n", + "def f(E):\n", + " Q=A*B*math.sqrt(E)\n", + " \n", + "I=(Ef,EF,f)\n", "\n", "#Result\n", "print(\"number of energy states per unit volume is\",I);" @@ -466,15 +468,14 @@ "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 18)", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m18\u001b[0m\n\u001b[1;33m function Q=f(E),Q=A*B*math.sqrt(E),endfunction\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + "output_type": "stream", + "stream": "stdout", + "text": [ + "('number of energy states per unit volume is', (4.960000000000001e-19, 4.992000000000001e-19, ))\n" ] } ], - "prompt_number": 25 + "prompt_number": 22 }, { "cell_type": "heading", diff --git a/How_to_think_like_a_computer_scientist_by_Allen_B_Downey/ch15.ipynb b/How_to_think_like_a_computer_scientist_by_Allen_B_Downey/ch15.ipynb index cc4b221f..8919462b 100755 --- a/How_to_think_like_a_computer_scientist_by_Allen_B_Downey/ch15.ipynb +++ b/How_to_think_like_a_computer_scientist_by_Allen_B_Downey/ch15.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "ch15" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -11,18 +11,40 @@ "cell_type": "heading", "level": 1, "metadata": {}, - "source": "Chapter 15 : File Input/Output and apmatrixes" + "source": [ + "Chapter 15 : File Input/Output and apmatrixes" + ] }, { "cell_type": "heading", "level": 3, "metadata": {}, - "source": "example 15.1 page no : 162\n" + "source": [ + "example 15.1 page no : 162\n" + ] }, { "cell_type": "code", "collapsed": false, - "input": "'''\nexample 15.1 page no : 162\n'''\ntry:\n fileName = \"a.txt\"\n f = open(fileName,\"r\")\nexcept:\n print \"Unable to open the file named \" , fileName;\n import sys\n sys.exit(0)\n\n# reading file line by line\n \nfor i in f.readlines():\n print i\n\nf.close() ", + "input": [ + "'''\n", + "example 15.1 page no : 162\n", + "'''\n", + "try:\n", + " fileName = \"a.txt\"\n", + " f = open(fileName,\"r\")\n", + "except:\n", + " print \"Unable to open the file named \" , fileName;\n", + " import sys\n", + " sys.exit(0)\n", + "\n", + "# reading file line by line\n", + " \n", + "for i in f.readlines():\n", + " print i\n", + "\n", + "f.close() " + ], "language": "python", "metadata": {}, "outputs": [ @@ -32,18 +54,22 @@ "output_type": "pyerr", "traceback": [ "An exception has occurred, use %tb to see the full traceback.\n", - "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n" + "\u001b[0;31mSystemExit\u001b[0m\u001b[0;31m:\u001b[0m 0\n" ] }, { "output_type": "stream", "stream": "stdout", - "text": "Unable to open the file named a.txt\n" + "text": [ + "Unable to open the file named a.txt\n" + ] }, { "output_type": "stream", "stream": "stderr", - "text": "To exit: use 'exit', 'quit', or Ctrl-D.\n" + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] } ], "prompt_number": 1 @@ -52,12 +78,37 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "example 15.2 page no : 163\n" + "source": [ + "example 15.2 page no : 163\n" + ] }, { "cell_type": "code", "collapsed": false, - "input": "'''\nexample 15.2 page no : 163\n'''\n\ntry:\n fileName = \"a.txt\"\n outputFile = \"b.txt\"\n f = open(fileName,\"r\")\n w = open(outputFile,\"w\")\nexcept:\n print \"Unable to open the file named \" , fileName;\n import sys\n sys.exit(0)\n\n# reading file line by line\n \nfor i in f.readlines():\n w.write(i)\n print i\n \nf.close()\nw.close() ", + "input": [ + "'''\n", + "example 15.2 page no : 163\n", + "'''\n", + "\n", + "try:\n", + " fileName = \"a.txt\"\n", + " outputFile = \"b.txt\"\n", + " f = open(fileName,\"r\")\n", + " w = open(outputFile,\"w\")\n", + "except:\n", + " print \"Unable to open the file named \" , fileName;\n", + " import sys\n", + " sys.exit(0)\n", + "\n", + "# reading file line by line\n", + " \n", + "for i in f.readlines():\n", + " w.write(i)\n", + " print i\n", + " \n", + "f.close()\n", + "w.close() " + ], "language": "python", "metadata": {}, "outputs": [ @@ -73,12 +124,16 @@ { "output_type": "stream", "stream": "stdout", - "text": "Unable to open the file named a.txt\n" + "text": [ + "Unable to open the file named a.txt\n" + ] }, { "output_type": "stream", "stream": "stderr", - "text": "To exit: use 'exit', 'quit', or Ctrl-D.\n" + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] } ], "prompt_number": 2 @@ -87,19 +142,67 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "example 15.3 page no : 167\n" + "source": [ + "example 15.3 page no : 167\n" + ] }, { "cell_type": "code", "collapsed": false, - "input": "'''\nexample 15.3 page no : 167\n'''\n\nclass Set:\n def __init__(self,n):\n self.elements = []\n self.numElements = 0\n\n def getNumElements(self):\n return self.numElements\n\n def getElement(self,i):\n if (i < self.numElements):\n return slef.elements[i];\n else:\n print \"Set index out of range.\" \n import sys\n sys.exit(0)\n\n def find(self,s):\n for i in range(self.numElements):\n if (self.elements[i] == s): \n return i;\n return -1;\n\n def add(self,s):\n # if the element is already in the set, return its index\n index = self.find(s);\n if (index != -1):\n return index;\n # if the apvector is full, double its size\n # add the new elements and return its index\n self.elements.append(s)\n self.numElements += 1\n return self.numElements - 1;\n\ncities= Set (2);\ncity1 = 'ahmedabad'\ncity2 = 'rajkot'\nindex1 = cities.add(city1);\nindex2 = cities.add(city2)\nprint index1, index2", + "input": [ + "'''\n", + "example 15.3 page no : 167\n", + "'''\n", + "\n", + "class Set:\n", + " def __init__(self,n):\n", + " self.elements = []\n", + " self.numElements = 0\n", + "\n", + " def getNumElements(self):\n", + " return self.numElements\n", + "\n", + " def getElement(self,i):\n", + " if (i < self.numElements):\n", + " return slef.elements[i];\n", + " else:\n", + " print \"Set index out of range.\" \n", + " import sys\n", + " sys.exit(0)\n", + "\n", + " def find(self,s):\n", + " for i in range(self.numElements):\n", + " if (self.elements[i] == s): \n", + " return i;\n", + " return -1;\n", + "\n", + " def add(self,s):\n", + " # if the element is already in the set, return its index\n", + " index = self.find(s);\n", + " if (index != -1):\n", + " return index;\n", + " # if the apvector is full, double its size\n", + " # add the new elements and return its index\n", + " self.elements.append(s)\n", + " self.numElements += 1\n", + " return self.numElements - 1;\n", + "\n", + "cities= Set (2);\n", + "city1 = 'ahmedabad'\n", + "city2 = 'rajkot'\n", + "index1 = cities.add(city1);\n", + "index2 = cities.add(city2)\n", + "print index1, index2" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "0 1\n" + "text": [ + "0 1\n" + ] } ], "prompt_number": 3 @@ -107,7 +210,7 @@ { "cell_type": "code", "collapsed": false, - "input": "", + "input": [], "language": "python", "metadata": {}, "outputs": [] @@ -115,7 +218,7 @@ { "cell_type": "code", "collapsed": false, - "input": "", + "input": [], "language": "python", "metadata": {}, "outputs": [] diff --git a/Mastering_C/.ipynb_checkpoints/chapter1-checkpoint.ipynb b/Mastering_C/.ipynb_checkpoints/chapter1-checkpoint.ipynb new file mode 100755 index 00000000..271dc0b9 --- /dev/null +++ b/Mastering_C/.ipynb_checkpoints/chapter1-checkpoint.ipynb @@ -0,0 +1,169 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:f3ff9d889b7b7951c347d942d053d9fde4d57e52c21d53b779e2930b738a9f69" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1: Introduction" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1, page no. 18" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello World\"\n", + "print \"Bye.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World\n", + "Bye\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2, page no. 24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello World\"\n", + "#This program will give error" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3, page no. 24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello World\"\n", + "print \"Bye.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World\n", + "Bye.\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4, page no. 24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello World\";print \"Bye.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World\n", + "Bye.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5, page no. 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"\\\n", + " Hello World\"\n", + "\n", + "print \"\\\n", + " Bye.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Hello World\n", + " Bye.\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Mastering_C/chapter1.ipynb b/Mastering_C/chapter1.ipynb index b1a0ed0e..271dc0b9 100755 --- a/Mastering_C/chapter1.ipynb +++ b/Mastering_C/chapter1.ipynb @@ -57,22 +57,21 @@ "cell_type": "code", "collapsed": false, "input": [ - "Print \"Hello World\"\n", + "print \"Hello World\"\n", "#This program will give error" ], "language": "python", "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 1)", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m Print \"Hello World\"\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World\n" ] } ], - "prompt_number": 2 + "prompt_number": 1 }, { "cell_type": "heading", diff --git a/Power_Electronics_by_P_S_Bimbhra/.ipynb_checkpoints/Chapter13_4-checkpoint.ipynb b/Power_Electronics_by_P_S_Bimbhra/.ipynb_checkpoints/Chapter13_4-checkpoint.ipynb new file mode 100755 index 00000000..a5664090 --- /dev/null +++ b/Power_Electronics_by_P_S_Bimbhra/.ipynb_checkpoints/Chapter13_4-checkpoint.ipynb @@ -0,0 +1,340 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13 : Power Factor Improvement" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.1, Page No 754" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "V_s=250.0\n", + "R_l=5.0\n", + "I_l=20.0\n", + "V_l1=math.sqrt(V_s**2-(R_l*I_l)**2)\n", + "reg1=(V_s-V_l1)/V_s*100 \n", + "pf1=1.0\n", + "\n", + "#Calculations\n", + "P_l1=V_l1*I_l*pf1 #load power\n", + "P_r1=V_s*I_l*pf1 #max powwible system rating\n", + "utf1=P_l1*100/P_r1 \n", + "pf2=0.5\n", + " #(.5*V_l)**2+(.866*V_l+R_l*I_l)**2=V_s**2\n", + " #after solving\n", + "V_l2=158.35 \n", + "reg2=(V_s-V_l2)/V_s*100 \n", + "P_l2=V_l2*I_l*pf2 #load power\n", + "P_r2=V_s*I_l #max powwible system rating\n", + "utf2=P_l2*100/P_r2 \n", + "\n", + "\n", + "#Results\n", + "print(\"for pf=1\")\n", + "print(\"load voltage=%.2f V\" %V_l1)\n", + "print(\"voltage regulation=%.2f\" %reg1)\n", + "print(\"system utilisation factor=%.3f\" %utf1)\n", + "print(\"energy consumed(in units)=%.1f\" %(P_l1/1000))\n", + "print(\"for pf=.5\")\n", + "print(\"load voltage=%.2f V\" %V_l2)\n", + "print(\"voltage regulation=%.2f\" %reg2)\n", + "print(\"system utilisation factor=%.3f\" %utf2)\n", + "print(\"energy consumed(in units)=%.2f\" %(P_l2/1000))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "for pf=1\n", + "load voltage=229.13 V\n", + "voltage regulation=8.35\n", + "system utilisation factor=91.652\n", + "energy consumed(in units)=4.6\n", + "for pf=.5\n", + "load voltage=158.35 V\n", + "voltage regulation=36.66\n", + "system utilisation factor=31.670\n", + "energy consumed(in units)=1.58\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.2, Page No 756" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "f=50.0\n", + "V_s=230.0\n", + "I_m1=2\n", + "pf1=.3\n", + "\n", + "#Calculations\n", + "I_c1=I_m1*math.sin(math.radians(math.degrees(math.acos(pf1))))\n", + "C1=I_c1/(2*math.pi*f*V_s) \n", + "I_m2=5\n", + "pf2=.5\n", + "I_c2=I_m2*math.sin(math.radians(math.degrees(math.acos(pf2))))\n", + "C2=I_c2/(2*math.pi*f*V_s) \n", + "I_m3=10\n", + "pf3=.7\n", + "I_c3=I_m3*math.sin(math.radians(math.degrees(math.acos(pf3))))\n", + "C3=I_c3/(2*math.pi*f*V_s) \n", + "\n", + "#Results\n", + "print(\"at no load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C1*10**6))\n", + "print(\"at half full load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C2*10**6))\n", + "print(\"at full load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C3*10**6))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "at no load\n", + "value of capacitance=26.404 uF\n", + "at half full load\n", + "value of capacitance=59.927 uF\n", + "at full load\n", + "value of capacitance=98.834 uF\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.3 Page No 764" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "I_c=10.0\n", + "f=50.0\n", + "V_s=230.0\n", + "\n", + "#Calculations\n", + "C=I_c/(2*math.pi*f*V_s) \n", + "I_l=10\n", + "L=V_s/(2*math.pi*f*I_l) \n", + "\n", + "#Results\n", + "print(\"value of capacitance=%.3f uF\" %(C*10**6))\n", + "print(\"value of inductor=%.3f mH\" %(L*1000))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of capacitance=138.396 uF\n", + "value of inductor=73.211 mH\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.4, Page No 765" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "V_s=230.0\n", + "I_L=10.0\n", + "X_L=V_s/I_L\n", + "I_f1=6.0\n", + " #B=2*a-math.sin(2*a)\n", + "B=2*math.pi-I_f1*math.pi*X_L/V_s\n", + "a=0\n", + "i=1.0\n", + "for a in range(1,360):\n", + " b=2*a*math.pi/180-math.sin(math.radians(2*a)) \n", + " if math.fabs(B-b)<=0.001 : #by hit and trial\n", + " i=2\n", + " break\n", + "print(\"firing angle of TCR = %.1f deg\" %a)\n", + " #(a-.01)*180/math.pi)\n", + " \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "firing angle of TCR = 359.0 deg\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.5 Page No 766" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "L=.01\n", + "\n", + "\n", + "#Calculations\n", + "print(\"for firing angle=90deg\")\n", + "a=90*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.0f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=120deg\")\n", + "a=120*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=150deg\")\n", + "a=150*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.2f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=170deg\")\n", + "a=170*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f H\" %L_eff)\n", + "print(\"for firing angle=175deg\")\n", + "a=175*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "\n", + "#Results\n", + "print(\"effective inductance=%.2f H\" %L_eff)\n", + "print(\"for firing angle=180deg\")\n", + "a=180*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f H\" %L_eff)\n", + " #random value at firing angle =180 is equivalent to infinity as in answer in book\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "for firing angle=90deg\n", + "effective inductance=10 mH\n", + "for firing angle=120deg\n", + "effective inductance=25.575 mH\n", + "for firing angle=150deg\n", + "effective inductance=173.40 mH\n", + "for firing angle=170deg\n", + "effective inductance=4.459 H\n", + "for firing angle=175deg\n", + "effective inductance=35.51 H\n", + "for firing angle=180deg\n", + "effective inductance=-128265253940037.750 H\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.6 Page No 766" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "Q=100.0*10**3\n", + "V_s=11.0*10**3\n", + "\n", + "#Calculations\n", + "f=50.0\n", + "L=V_s**2/(2*math.pi*f*Q) \n", + "\n", + "#Results\n", + "print(\"effective inductance=%.4f H\" %L)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "effective inductance=3.8515 H\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Power_Electronics_by_P_S_Bimbhra/Chapter13_4.ipynb b/Power_Electronics_by_P_S_Bimbhra/Chapter13_4.ipynb index 62d2a926..a5664090 100755 --- a/Power_Electronics_by_P_S_Bimbhra/Chapter13_4.ipynb +++ b/Power_Electronics_by_P_S_Bimbhra/Chapter13_4.ipynb @@ -1,342 +1,340 @@ -{ - "metadata": { - "name": "" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 13 : Power Factor Improvement" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.1, Page No 754" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "V_s=250.0\n", - "R_l=5.0\n", - "I_l=20.0\n", - "V_l1=math.sqrt(V_s**2-(R_l*I_l)**2)\n", - "reg2=(V_s-V_l1)/V_s*100 \n", - "pf1=1.0\n", - "\n", - "#Calculations\n", - "P_l1=V_l1*I_l*pf1 #load power\n", - "P_r1=V_s*I_l*pf1 #max powwible system rating\n", - "utf1=P_l1*100/P_r1 \n", - "pf2=0.5\n", - " #(.5*V_l)**2+(.866*V_l+R_l*I_l)**2=V_s**2\n", - " #after solving\n", - "V_l2=158.35 \n", - "reg2=(V_s-V_l2)/V_s*100 \n", - "P_l2=V_l2*I_l*pf2 #load power\n", - "P_r2=V_s*I_l #max powwible system rating\n", - "utf2=P_l2*100/P_r2 \n", - "\n", - "\n", - "#Results\n", - "print(\"for pf=1\")\n", - "print(\"load voltage=%.2f V\" %V_l1)\n", - "print(\"voltage regulation=%.2f\" %reg1)\n", - "print(\"system utilisation factor=%.3f\" %utf1)\n", - "print(\"energy consumed(in units)=%.1f\" %(P_l1/1000))\n", - "print(\"for pf=.5\")\n", - "print(\"load voltage=%.2f V\" %V_l2)\n", - "print(\"voltage regulation=%.2f\" %reg2)\n", - "print(\"system utilisation factor=%.3f\" %utf2)\n", - "print(\"energy consumed(in units)=%.2f\" %(P_l2/1000))\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'reg1' is not defined", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 25\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"for pf=1\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 26\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"load voltage=%.2f V\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[0mV_l1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 27\u001b[1;33m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"voltage regulation=%.2f\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[0mreg1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 28\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"system utilisation factor=%.3f\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[0mutf1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 29\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"energy consumed(in units)=%.1f\"\u001b[0m \u001b[1;33m%\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mP_l1\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;36m1000\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: name 'reg1' is not defined" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "for pf=1\n", - "load voltage=229.13 V\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.2, Page No 756" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "f=50.0\n", - "V_s=230.0\n", - "I_m1=2\n", - "pf1=.3\n", - "\n", - "#Calculations\n", - "I_c1=I_m1*math.sin(math.radians(math.degrees(math.acos(pf1))))\n", - "C1=I_c1/(2*math.pi*f*V_s) \n", - "I_m2=5\n", - "pf2=.5\n", - "I_c2=I_m2*math.sin(math.radians(math.degrees(math.acos(pf2))))\n", - "C2=I_c2/(2*math.pi*f*V_s) \n", - "I_m3=10\n", - "pf3=.7\n", - "I_c3=I_m3*math.sin(math.radians(math.degrees(math.acos(pf3))))\n", - "C3=I_c3/(2*math.pi*f*V_s) \n", - "\n", - "#Results\n", - "print(\"at no load\")\n", - "print(\"value of capacitance=%.3f uF\" %(C1*10**6))\n", - "print(\"at half full load\")\n", - "print(\"value of capacitance=%.3f uF\" %(C2*10**6))\n", - "print(\"at full load\")\n", - "print(\"value of capacitance=%.3f uF\" %(C3*10**6))" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "at no load\n", - "value of capacitance=26.404 uF\n", - "at half full load\n", - "value of capacitance=59.927 uF\n", - "at full load\n", - "value of capacitance=98.834 uF\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.3 Page No 764" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "I_c=10.0\n", - "f=50.0\n", - "V_s=230.0\n", - "\n", - "#Calculations\n", - "C=I_c/(2*math.pi*f*V_s) \n", - "I_l=10\n", - "L=V_s/(2*math.pi*f*I_l) \n", - "\n", - "#Results\n", - "print(\"value of capacitance=%.3f uF\" %(C*10**6))\n", - "print(\"value of inductor=%.3f mH\" %(L*1000))\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "value of capacitance=138.396 uF\n", - "value of inductor=73.211 mH\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.4, Page No 765" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "V_s=230.0\n", - "I_L=10.0\n", - "X_L=V_s/I_L\n", - "I_f1=6.0\n", - " #B=2*a-math.sin(2*a)\n", - "B=2*math.pi-I_f1*math.pi*X_L/V_s\n", - "a=0\n", - "i=1.0\n", - "for a in range(1,360):\n", - " b=2*a*math.pi/180-math.sin(math.radians(2*a)) \n", - " if math.fabs(B-b)<=0.001 : #by hit and trial\n", - " i=2\n", - " break\n", - "print(\"firing angle of TCR = %.1f deg\" %a)\n", - " #(a-.01)*180/math.pi)\n", - " \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "firing angle of TCR = 359.0 deg\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.5 Page No 766" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "L=.01\n", - "\n", - "\n", - "#Calculations\n", - "print(\"for firing angle=90deg\")\n", - "a=90*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "print(\"effective inductance=%.0f mH\" %(L_eff*1000))\n", - "print(\"for firing angle=120deg\")\n", - "a=120*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "print(\"effective inductance=%.3f mH\" %(L_eff*1000))\n", - "print(\"for firing angle=150deg\")\n", - "a=150*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "print(\"effective inductance=%.2f mH\" %(L_eff*1000))\n", - "print(\"for firing angle=170deg\")\n", - "a=170*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "print(\"effective inductance=%.3f H\" %L_eff)\n", - "print(\"for firing angle=175deg\")\n", - "a=175*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "\n", - "#Results\n", - "print(\"effective inductance=%.2f H\" %L_eff)\n", - "print(\"for firing angle=180deg\")\n", - "a=180*math.pi/180\n", - "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", - "print(\"effective inductance=%.3f H\" %L_eff)\n", - " #random value at firing angle =180 is equivalent to infinity as in answer in book\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "for firing angle=90deg\n", - "effective inductance=10 mH\n", - "for firing angle=120deg\n", - "effective inductance=25.575 mH\n", - "for firing angle=150deg\n", - "effective inductance=173.40 mH\n", - "for firing angle=170deg\n", - "effective inductance=4.459 H\n", - "for firing angle=175deg\n", - "effective inductance=35.51 H\n", - "for firing angle=180deg\n", - "effective inductance=-128265253940037.750 H\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.6 Page No 766" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "#initialisation of variables\n", - "Q=100.0*10**3\n", - "V_s=11.0*10**3\n", - "\n", - "#Calculations\n", - "f=50.0\n", - "L=V_s**2/(2*math.pi*f*Q) \n", - "\n", - "#Results\n", - "print(\"effective inductance=%.4f H\" %L)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "effective inductance=3.8515 H\n" - ] - } - ], - "prompt_number": 7 - } - ], - "metadata": {} - } - ] +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13 : Power Factor Improvement" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.1, Page No 754" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "V_s=250.0\n", + "R_l=5.0\n", + "I_l=20.0\n", + "V_l1=math.sqrt(V_s**2-(R_l*I_l)**2)\n", + "reg1=(V_s-V_l1)/V_s*100 \n", + "pf1=1.0\n", + "\n", + "#Calculations\n", + "P_l1=V_l1*I_l*pf1 #load power\n", + "P_r1=V_s*I_l*pf1 #max powwible system rating\n", + "utf1=P_l1*100/P_r1 \n", + "pf2=0.5\n", + " #(.5*V_l)**2+(.866*V_l+R_l*I_l)**2=V_s**2\n", + " #after solving\n", + "V_l2=158.35 \n", + "reg2=(V_s-V_l2)/V_s*100 \n", + "P_l2=V_l2*I_l*pf2 #load power\n", + "P_r2=V_s*I_l #max powwible system rating\n", + "utf2=P_l2*100/P_r2 \n", + "\n", + "\n", + "#Results\n", + "print(\"for pf=1\")\n", + "print(\"load voltage=%.2f V\" %V_l1)\n", + "print(\"voltage regulation=%.2f\" %reg1)\n", + "print(\"system utilisation factor=%.3f\" %utf1)\n", + "print(\"energy consumed(in units)=%.1f\" %(P_l1/1000))\n", + "print(\"for pf=.5\")\n", + "print(\"load voltage=%.2f V\" %V_l2)\n", + "print(\"voltage regulation=%.2f\" %reg2)\n", + "print(\"system utilisation factor=%.3f\" %utf2)\n", + "print(\"energy consumed(in units)=%.2f\" %(P_l2/1000))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "for pf=1\n", + "load voltage=229.13 V\n", + "voltage regulation=8.35\n", + "system utilisation factor=91.652\n", + "energy consumed(in units)=4.6\n", + "for pf=.5\n", + "load voltage=158.35 V\n", + "voltage regulation=36.66\n", + "system utilisation factor=31.670\n", + "energy consumed(in units)=1.58\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.2, Page No 756" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "f=50.0\n", + "V_s=230.0\n", + "I_m1=2\n", + "pf1=.3\n", + "\n", + "#Calculations\n", + "I_c1=I_m1*math.sin(math.radians(math.degrees(math.acos(pf1))))\n", + "C1=I_c1/(2*math.pi*f*V_s) \n", + "I_m2=5\n", + "pf2=.5\n", + "I_c2=I_m2*math.sin(math.radians(math.degrees(math.acos(pf2))))\n", + "C2=I_c2/(2*math.pi*f*V_s) \n", + "I_m3=10\n", + "pf3=.7\n", + "I_c3=I_m3*math.sin(math.radians(math.degrees(math.acos(pf3))))\n", + "C3=I_c3/(2*math.pi*f*V_s) \n", + "\n", + "#Results\n", + "print(\"at no load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C1*10**6))\n", + "print(\"at half full load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C2*10**6))\n", + "print(\"at full load\")\n", + "print(\"value of capacitance=%.3f uF\" %(C3*10**6))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "at no load\n", + "value of capacitance=26.404 uF\n", + "at half full load\n", + "value of capacitance=59.927 uF\n", + "at full load\n", + "value of capacitance=98.834 uF\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.3 Page No 764" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "I_c=10.0\n", + "f=50.0\n", + "V_s=230.0\n", + "\n", + "#Calculations\n", + "C=I_c/(2*math.pi*f*V_s) \n", + "I_l=10\n", + "L=V_s/(2*math.pi*f*I_l) \n", + "\n", + "#Results\n", + "print(\"value of capacitance=%.3f uF\" %(C*10**6))\n", + "print(\"value of inductor=%.3f mH\" %(L*1000))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "value of capacitance=138.396 uF\n", + "value of inductor=73.211 mH\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.4, Page No 765" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "V_s=230.0\n", + "I_L=10.0\n", + "X_L=V_s/I_L\n", + "I_f1=6.0\n", + " #B=2*a-math.sin(2*a)\n", + "B=2*math.pi-I_f1*math.pi*X_L/V_s\n", + "a=0\n", + "i=1.0\n", + "for a in range(1,360):\n", + " b=2*a*math.pi/180-math.sin(math.radians(2*a)) \n", + " if math.fabs(B-b)<=0.001 : #by hit and trial\n", + " i=2\n", + " break\n", + "print(\"firing angle of TCR = %.1f deg\" %a)\n", + " #(a-.01)*180/math.pi)\n", + " \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "firing angle of TCR = 359.0 deg\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.5 Page No 766" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "L=.01\n", + "\n", + "\n", + "#Calculations\n", + "print(\"for firing angle=90deg\")\n", + "a=90*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.0f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=120deg\")\n", + "a=120*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=150deg\")\n", + "a=150*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.2f mH\" %(L_eff*1000))\n", + "print(\"for firing angle=170deg\")\n", + "a=170*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f H\" %L_eff)\n", + "print(\"for firing angle=175deg\")\n", + "a=175*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "\n", + "#Results\n", + "print(\"effective inductance=%.2f H\" %L_eff)\n", + "print(\"for firing angle=180deg\")\n", + "a=180*math.pi/180\n", + "L_eff=math.pi*L/(2*math.pi-2*a+math.sin(2*a)) \n", + "print(\"effective inductance=%.3f H\" %L_eff)\n", + " #random value at firing angle =180 is equivalent to infinity as in answer in book\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "for firing angle=90deg\n", + "effective inductance=10 mH\n", + "for firing angle=120deg\n", + "effective inductance=25.575 mH\n", + "for firing angle=150deg\n", + "effective inductance=173.40 mH\n", + "for firing angle=170deg\n", + "effective inductance=4.459 H\n", + "for firing angle=175deg\n", + "effective inductance=35.51 H\n", + "for firing angle=180deg\n", + "effective inductance=-128265253940037.750 H\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.6 Page No 766" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "#initialisation of variables\n", + "Q=100.0*10**3\n", + "V_s=11.0*10**3\n", + "\n", + "#Calculations\n", + "f=50.0\n", + "L=V_s**2/(2*math.pi*f*Q) \n", + "\n", + "#Results\n", + "print(\"effective inductance=%.4f H\" %L)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "effective inductance=3.8515 H\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] } \ No newline at end of file diff --git a/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb b/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb new file mode 100755 index 00000000..c25523b7 --- /dev/null +++ b/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb @@ -0,0 +1,175 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:aaf3603d1f605477459dd54990dcc4c8c154c9c808805468e92c30fde9487343" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Chapter 14: File input/output" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 14.1, Page number: 253" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Variable declaration\n", + "import os\n", + "count = 0\n", + "in_file = open ('input.txt', 'r')\n", + " \n", + "# Calculation and result\n", + "if not os.path.exists ('input.txt') :\n", + " print ('Cannot open input.txt\\n')\n", + "\n", + "while (1) :\n", + " ch = in_file.read(1)\n", + " if not ch :\n", + " break\n", + " count += 1\n", + "\n", + "print ('Number of characters in input.txt is %d\\n' % count)\n", + "\n", + "in_file.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number of characters in input.txt is 0\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 14.3, Page number: 257" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "# Variable declaration\n", + "import sys\n", + "import os\n", + "in_file = open ('input.txt', 'r')\n", + " \n", + "# Calculation and result\n", + "if not os.path.exists ('input.txt') :\n", + " print ('Could not open file\\n')\n", + " sys.exit(1)\n", + "print ('File found\\n')\n", + "\n", + "in_file.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "File found\n", + "\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 14.4, Page number: 260" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Variable declaration\n", + "import sys\n", + "import os\n", + "out_file = open ('test.out', 'w')\n", + " \n", + "# Calculation and result\n", + "if not os.path.exists ('test.out') :\n", + " print ('Cannot open output file\\n')\n", + " sys.exit(1)\n", + "\n", + "for cur_char in range (0, 128) :\n", + " out_file.write(str (cur_char))\n", + " out_file.write('\\n')\n", + "\n", + "out_file.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 14.5, Page number: 267" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "# Variable declaration\n", + "txt_file = open ('input.txt')\n", + "\n", + "source_content = txt_file.read()\n", + "\n", + "target = open ('output.txt', 'w')\n", + "\n", + "# Calculation and result\n", + "target.write(source_content)\n", + "print ('Content copied')\n", + "\n", + "target.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Practical_C_Programming/.ipynb_checkpoints/Chapter_15_1-checkpoint.ipynb b/Practical_C_Programming/.ipynb_checkpoints/Chapter_15_1-checkpoint.ipynb new file mode 100755 index 00000000..05286d0f --- /dev/null +++ b/Practical_C_Programming/.ipynb_checkpoints/Chapter_15_1-checkpoint.ipynb @@ -0,0 +1,351 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:23b3891085deb8af52412d44380b6187a4110d7e026531ec90b3b2ae79d61d0f" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 15: Debugging and optimization" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.1, Page number: 275" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Function declaration\n", + "def lookup (name) :\n", + " lists = ['John', 'Jim', 'Jane', 'Clyde']\n", + " result = 0\n", + "\n", + " for index in range (0, 4) :\n", + " if (lists[index] == name) :\n", + " result = 1\n", + " break\n", + " \n", + " return result\n", + "\n", + "# Calculation and result\n", + "name = 'John'\n", + "\n", + "if (lookup (name)) :\n", + " print ('%s is in the list\\n' % name)\n", + "else :\n", + " print ('%s is not in the list\\n' % name)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "John is in the list\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.6, Page number: 288" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Variable and function declaration\n", + "seven_count = 0\n", + "three_count = 0\n", + "data = []\n", + "\n", + "def get_data (data) :\n", + " for i in range (0, 5) :\n", + " x = 3\n", + " data.append(int(x))\n", + " print (data)\n", + "\n", + "# Calculation\n", + "get_data (data)\n", + "for index in range (0, 5) :\n", + " if data[index] == 3 :\n", + " three_count += 1\n", + "\n", + " if data[index] == 7 :\n", + " seven_count += 1\n", + "\n", + "# Result\n", + "print ('Threes %d Sevens %d' % (three_count, seven_count))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "[3, 3, 3, 3, 3]\n", + "Threes 5 Sevens 0\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.7, Page number: 292" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Variable declaration\n", + "import sys\n", + "import os\n", + "in_file = open ('numbers.dat', 'r')\n", + "\n", + "data = []\n", + "max_count = 0\n", + " \n", + "# Calculation and result\n", + "if not os.path.exists ('numbers.dat') :\n", + " print ('Error:Unable to open numbers.dat\\n')\n", + " sys.exit(1)\n", + "\n", + "for line in in_file :\n", + " data.append(line)\n", + " max_count += 1\n", + "\n", + "while (1) :\n", + " search = 6\n", + " \n", + " if (search == -1) :\n", + " break\n", + "\n", + " low = 0\n", + " high = max_count\n", + "\n", + " while (1) :\n", + " mid = (low + high) / 2\n", + " middle = int (mid) \n", + "\n", + " if (int (data[middle]) == search) :\n", + " print ('Found at index %d\\n' % (middle + 1))\n", + " break\n", + "\n", + " if (low == high) :\n", + " print ('Not found\\n')\n", + " break\n", + "\n", + " if (int (data[middle]) < search) :\n", + " low = middle\n", + " else :\n", + " high = middle \n", + "\n", + "in_file.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": "*" + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.8, Page number: 300" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "# Variable declaration\n", + "import sys\n", + "import os\n", + "in_file = open ('numbers.dat', 'r')\n", + "\n", + "data = []\n", + "max_count = 0\n", + " \n", + "# Calculation and result\n", + "if not os.path.exists ('numbers.dat') :\n", + " print ('Error:Unable to open numbers.dat\\n')\n", + " sys.exit(1)\n", + "\n", + "for line in in_file :\n", + " data.append(line)\n", + " max_count += 1\n", + "\n", + "while (1) :\n", + " search = 14\n", + " \n", + " if (search == -1) :\n", + " break\n", + "\n", + " low = 0\n", + " high = max_count\n", + "\n", + " while (1) :\n", + " mid = (low + high) / 2\n", + " middle = int (mid) \n", + "\n", + " if (int (data[middle]) == search) :\n", + " print ('Found at index %d\\n' % (middle + 1))\n", + " break\n", + "\n", + " if (low == high) :\n", + " print ('Not found\\n')\n", + " break\n", + "\n", + " if (int (data[middle]) < search) :\n", + " low = middle\n", + " else :\n", + " high = middle \n", + "\n", + "in_file.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": "*" + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.10, Page number: 304" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "# Variable declaration\n", + "i = 1\n", + "j = 1\n", + "\n", + "# Calculation and result\n", + "print ('Starting\\n')\n", + "print ('Before divide...')\n", + "i = i / j\n", + "print ('After\\n')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Starting\n", + "\n", + "Before divide...\n", + "After\n", + "\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 15.11, Page number: 304" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "from __future__ import division\n", + "# Variable declaration\n", + "import sys\n", + "i = 1\n", + "j = 1\n", + "\n", + "# Calculation and result\n", + "print ('Starting\\n')\n", + "sys.stdout.flush()\n", + "print ('Before divide...')\n", + "sys.stdout.flush()\n", + "i = i / j\n", + "print ('After\\n')\n", + "sys.stdout.flush()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Starting\n", + "\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Before divide...\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "After\n", + "\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Practical_C_Programming/Chapter_14_1.ipynb b/Practical_C_Programming/Chapter_14_1.ipynb index 6d3c736e..c25523b7 100755 --- a/Practical_C_Programming/Chapter_14_1.ipynb +++ b/Practical_C_Programming/Chapter_14_1.ipynb @@ -52,17 +52,15 @@ "metadata": {}, "outputs": [ { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'input.txt'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mcount\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0min_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'input.txt'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;31m# Calculation and result\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'input.txt'" + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number of characters in input.txt is 0\n", + "\n" ] } ], - "prompt_number": 1 + "prompt_number": 2 }, { "cell_type": "heading", @@ -84,7 +82,7 @@ "in_file = open ('input.txt', 'r')\n", " \n", "# Calculation and result\n", - "if not os.path.exists (name) :\n", + "if not os.path.exists ('input.txt') :\n", " print ('Could not open file\\n')\n", " sys.exit(1)\n", "print ('File found\\n')\n", @@ -95,17 +93,15 @@ "metadata": {}, "outputs": [ { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'input.txt'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0min_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'input.txt'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;31m# Calculation and result\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'input.txt'" + "output_type": "stream", + "stream": "stdout", + "text": [ + "File found\n", + "\n" ] } ], - "prompt_number": 2 + "prompt_number": 5 }, { "cell_type": "heading", diff --git a/Practical_C_Programming/Chapter_15_1.ipynb b/Practical_C_Programming/Chapter_15_1.ipynb index 34a86a67..05286d0f 100755 --- a/Practical_C_Programming/Chapter_15_1.ipynb +++ b/Practical_C_Programming/Chapter_15_1.ipynb @@ -173,19 +173,8 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'numbers.dat'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0min_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'numbers.dat'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mdata\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;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'numbers.dat'" - ] - } - ], - "prompt_number": 5 + "outputs": [], + "prompt_number": "*" }, { "cell_type": "heading", @@ -248,19 +237,8 @@ ], "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'numbers.dat'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0min_file\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'numbers.dat'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mdata\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;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'numbers.dat'" - ] - } - ], - "prompt_number": 6 + "outputs": [], + "prompt_number": "*" }, { "cell_type": "heading", @@ -277,7 +255,7 @@ "\n", "# Variable declaration\n", "i = 1\n", - "j = 0\n", + "j = 1\n", "\n", "# Calculation and result\n", "print ('Starting\\n')\n", @@ -288,27 +266,19 @@ "language": "python", "metadata": {}, "outputs": [ - { - "ename": "ZeroDivisionError", - "evalue": "integer division or modulo by zero", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'Starting\\n'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'Before divide...'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mi\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mj\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 13\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'After\\n'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" - ] - }, { "output_type": "stream", "stream": "stdout", "text": [ "Starting\n", "\n", - "Before divide...\n" + "Before divide...\n", + "After\n", + "\n" ] } ], - "prompt_number": 7 + "prompt_number": 9 }, { "cell_type": "heading", @@ -322,11 +292,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", + "from __future__ import division\n", "# Variable declaration\n", "import sys\n", "i = 1\n", - "j = 0\n", + "j = 1\n", "\n", "# Calculation and result\n", "print ('Starting\\n')\n", @@ -356,17 +326,23 @@ ] }, { - "ename": "ZeroDivisionError", - "evalue": "integer division or modulo by zero", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'Before divide...'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstdout\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 15\u001b[1;33m \u001b[0mi\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mj\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 16\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'After\\n'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 17\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstdout\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" + "output_type": "stream", + "stream": "stdout", + "text": [ + "After\n", + "\n" ] } ], "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] } ], "metadata": {} diff --git a/Practical_C_Programming/numbers.dat b/Practical_C_Programming/numbers.dat new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/Practical_C_Programming/numbers.dat @@ -0,0 +1 @@ +0 diff --git a/Practical_C_Programming/numbers.dat~ b/Practical_C_Programming/numbers.dat~ new file mode 100644 index 00000000..e69de29b diff --git a/Principles_Of_Electronic_Communication_Systems_by_L_E_Frenze/chapter22.ipynb b/Principles_Of_Electronic_Communication_Systems_by_L_E_Frenze/chapter22.ipynb new file mode 100755 index 00000000..2fc3916b --- /dev/null +++ b/Principles_Of_Electronic_Communication_Systems_by_L_E_Frenze/chapter22.ipynb @@ -0,0 +1,94 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:d66b7b0a5ebd4fcdf9eb24f98ae81ac03aa2dcdb229f576b47a170647bd9ea49" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 22 Communication tests and measurments" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 22.1 Page no 854" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Given\n", + "Vp=8 #volts\n", + "R=75 #Ohm\n", + "\n", + "#Calculation\n", + "Vmax=0.707*Vp\n", + "P=Vmax**2/R\n", + "\n", + "#Result\n", + "print\"Power is dissipated in the load is \",round(P,4),\"Watt\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Power is dissipated in the load is 0.4265 Watt\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 22.2 Page no 857" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Given\n", + "Pf=380.0 #Watt\n", + "Pr=40 #Watt\n", + "\n", + "#Calculation\n", + "import math\n", + "m=math.sqrt(Pr/Pf)\n", + "SWR=(1+m)/(1-m)\n", + "print\"SWR= \",round(SWR,2)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "SWR= 1.96\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Programming_With_Java_A_Primer/.ipynb_checkpoints/chapter13-checkpoint.ipynb b/Programming_With_Java_A_Primer/.ipynb_checkpoints/chapter13-checkpoint.ipynb new file mode 100755 index 00000000..28830641 --- /dev/null +++ b/Programming_With_Java_A_Primer/.ipynb_checkpoints/chapter13-checkpoint.ipynb @@ -0,0 +1,266 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:5b64344dd4b10e210167de1e2d127d9539461b4485363c51a2c3ddba9df7db38" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13: Managing Errors & Exceptions" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.1, page no. 231" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\"\"\"\n", + "there is no need of semicolon. We will show error for something else\n", + "\"\"\"\n", + "\n", + "print \"Hello Python...\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello Python...\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.2, page no. 232" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = 10\n", + "b = 5\n", + "c = 5\n", + "x = a/(b-c) #It will show ZeroDivisionError\n", + "print \"x = \", x\n", + "y = a/(b+c)\n", + "print \"y = \", y" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "ZeroDivisionError", + "evalue": "division by zero", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"x = \"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.3 page no : 235" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = 10\n", + "b = 5\n", + "c = 5\n", + "try:\n", + " x = a/(b-c)\n", + "except Exception,e :\n", + " print \"Division by zero\"\n", + "y = a/(b+c)\n", + "print \"y = \",y" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Division by zero\n", + "y = 1\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.4 page no : 236" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "invalid = 0\n", + "count = 0\n", + "for i in sys.argv:\n", + " try:\n", + " a = int(i)\n", + " except:\n", + " invalid += 1\n", + " print \"Invalid number\" , i\n", + " continue\n", + " count += 1\n", + "\n", + "print \"Valid Numbers : \" ,count\n", + "print \"Invalid numbers \",invalid\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Invalid number -c\n", + "Invalid number -f\n", + "Invalid number /tmp/tmp1tOqar/profile_default/security/kernel-082ebfe6-5650-4ba4-8bcf-cd17bc99af7a.json\n", + "Invalid number --IPKernelApp.parent_appname='ipython-notebook'\n", + "Invalid number --profile-dir\n", + "Invalid number /tmp/tmp1tOqar/profile_default\n", + "Invalid number --parent=1\n", + "Valid Numbers : 0\n", + "Invalid numbers 7\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "example 13.5, page no. 239" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = [5,10]\n", + "b = 5\n", + "try:\n", + " x = a[2]/b - a[1]\n", + "except AssertionError:\n", + " print \"AssertionError:\"\n", + "except IndexError:\n", + " print \"Array Index Error\"\n", + "except Exception:\n", + " print \"Any Error\"\n", + "y = a[1]/a[0]\n", + "print \"y = \" , y " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Array Index Error\n", + "y = 2\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.6 page no : 239" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "x = 5\n", + "y = 1000\n", + "\n", + "class MyException(Exception):\n", + " def __init__(self, message):\n", + " Exception.__init__(self, message)\n", + " def error(self):\n", + " print self.message\n", + "\n", + "try:\n", + " z = x/y\n", + " if(z<0.01):\n", + " raise MyException(\"Number is too small\")\n", + "except MyException, error:\n", + " print \"Caught MyException\"\n", + " print error.message\n", + "finally:\n", + " print \"I am always here\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Caught MyException\n", + "Number is too small\n", + "I am always here\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Programming_With_Java_A_Primer/chapter13.ipynb b/Programming_With_Java_A_Primer/chapter13.ipynb index 7c07d269..28830641 100755 --- a/Programming_With_Java_A_Primer/chapter13.ipynb +++ b/Programming_With_Java_A_Primer/chapter13.ipynb @@ -33,21 +33,20 @@ "there is no need of semicolon. We will show error for something else\n", "\"\"\"\n", "\n", - "print \"Hello Python..." + "print \"Hello Python...\"" ], "language": "python", "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "EOL while scanning string literal (, line 7)", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m print \"Hello Python...\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n" + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello Python...\n" ] } ], - "prompt_number": 1 + "prompt_number": 2 }, { "cell_type": "heading", @@ -65,7 +64,7 @@ "a = 10\n", "b = 5\n", "c = 5\n", - "x = a/(b-c)\n", + "x = a/(b-c) #It will show ZeroDivisionError\n", "print \"x = \", x\n", "y = a/(b+c)\n", "print \"y = \", y" @@ -75,16 +74,16 @@ "outputs": [ { "ename": "ZeroDivisionError", - "evalue": "integer division or modulo by zero", + "evalue": "division by zero", "output_type": "pyerr", "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero" + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"x = \"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" ] } ], - "prompt_number": 2 + "prompt_number": 5 }, { "cell_type": "heading", diff --git a/Programming_With_Java_A_Primer/chapter17.ipynb b/Programming_With_Java_A_Primer/chapter17.ipynb index c8344546..75e227d6 100755 --- a/Programming_With_Java_A_Primer/chapter17.ipynb +++ b/Programming_With_Java_A_Primer/chapter17.ipynb @@ -45,14 +45,14 @@ "evalue": "The value b cannot be zero", "output_type": "pyerr", "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mAssertionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"The result is: \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mdiv\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mDivision\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0massertcheck\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36massertcheck\u001b[1;34m(self, a, b)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mDivision\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 6\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0massertcheck\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m!=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"The value b cannot be zero\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"The result is: \"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mAssertionError\u001b[0m: The value b cannot be zero" + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"The result is: \"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mdiv\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDivision\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mdiv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0massertcheck\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36massertcheck\u001b[0;34m(self, a, b)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mDivision\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0massertcheck\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32massert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m!=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"The value b cannot be zero\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"The result is: \"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAssertionError\u001b[0m: The value b cannot be zero" ] } ], - "prompt_number": 3 + "prompt_number": 1 } ], "metadata": {} diff --git a/Programming_in_C/.ipynb_checkpoints/Chapter_16-checkpoint.ipynb b/Programming_in_C/.ipynb_checkpoints/Chapter_16-checkpoint.ipynb new file mode 100755 index 00000000..535875b5 --- /dev/null +++ b/Programming_in_C/.ipynb_checkpoints/Chapter_16-checkpoint.ipynb @@ -0,0 +1,294 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 16: Input and Output Operations in Python" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Program 16.1, Page number: 350" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def main():\n", + "\n", + " #Variable Declaration\n", + " c='X'\n", + " s=\"abcdefghijklmnopqrstuvwxyz\"\n", + " i=425\n", + " j=17\n", + " u=0xf179\n", + " l=75000\n", + " L=0x1234567812345678\n", + " f=12.978\n", + " d=-97.4583\n", + " cp=c\n", + " ip=i\n", + " \n", + "\n", + " #Print Integers\n", + " print(\"Integers:\\n\")\n", + " print(\"%i %o %x %u\" %(i,i,i,i))\n", + " print(\"%x %X %#x %#X\" %(i,i,i,i))\n", + " print(\"%+i % i %07i %.7i\" %(i,i,i, i))\n", + " print(\"%i %o %x %u\" %(j,j,j,j))\n", + " print(\"%i %o %x %u\" %(u,u,u,u))\n", + " print(\"%ld %lo %lx %lu\" %(l,l,l,l))\n", + " print(\"%li %lo %lx %lu\" %(L,L,L, L))\n", + "\n", + " #Print Floats & Doubles\n", + " print(\"\\nFloats and Doubles:\")\n", + " print(\"%f %e %g\"%( f, f, f))\n", + " print(\"%.2f %.2e\"%( f, f))\n", + " print(\"%.0f %.0e\"%( f, f))\n", + " print(\"%7.2f %7.2e\"%( f, f))\n", + " print(\"%f %e %g\"%( d, d, d))\n", + " print(\"%.*f\"%( 3, d))\n", + " print(\"%*.*f\" %(8, 2, d))\n", + "\n", + " #Print Characters\n", + " print(\"\\nCharacters:\")\n", + " print(\"%c\"%(c))\n", + " print(\"%3c%3c\"%( c, c))\n", + " print(\"{0:x} \".format(ord(c))) \n", + "\n", + " #Print Strings\n", + " print(\"\\nStrings:\")\n", + " print(\"%s\"%(s))\n", + " print(\"%.5s\"%(s))\n", + " print(\"%30s\"%(s))\n", + " print(\"%20.5s\"%(s))\n", + " print(\"%-20.5s\"%(s))\n", + "\n", + " #Print variables pointers\n", + " print(\"\\nPointers:\")\n", + " print(\"{0:x} {1:x}\\n\".format(int(ip),ord(cp)))\n", + "\n", + " print(\"This%n is fun.\")\n", + " print(\"c1 = %i, c2 = %i\\n\"%(4, 12))\n", + "\n", + "\n", + "if __name__=='__main__':\n", + " main()\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Integers:\n", + "\n", + "425 651 1a9 425\n", + "1a9 1A9 0x1a9 0X1A9\n", + "+425 425 0000425 0000425\n", + "17 21 11 17\n", + "61817 170571 f179 61817\n", + "75000 222370 124f8 75000\n", + "1311768465173141112 110642547402215053170 1234567812345678 1311768465173141112\n", + "\n", + "Floats and Doubles:\n", + "12.978000 1.297800e+01 12.978\n", + "12.98 1.30e+01\n", + "13 1e+01\n", + " 12.98 1.30e+01\n", + "-97.458300 -9.745830e+01 -97.4583\n", + "-97.458\n", + " -97.46\n", + "\n", + "Characters:\n", + "X\n", + " X X\n", + "58 \n", + "\n", + "Strings:\n", + "abcdefghijklmnopqrstuvwxyz\n", + "abcde\n", + " abcdefghijklmnopqrstuvwxyz\n", + " abcde\n", + "abcde \n", + "\n", + "Pointers:\n", + "1a9 58\n", + "\n", + "This%n is fun.\n", + "c1 = 4, c2 = 12\n", + "\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Program 16.2, Page number: 362" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "\n", + "def main():\n", + " \n", + " while (True):\n", + " #c=raw_input() #User Input\n", + " c=\"this is a sample text\" #Dummy text\n", + " print(c); #Display Result\n", + " \n", + " #Un-comment this while executing from terminal/command line\n", + " #if(c==\"EOF\"): #Check Exit condition\n", + " sys.exit()\n", + " \n", + "\n", + "if __name__=='__main__':\n", + " main()\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "SystemExit", + "evalue": "", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[1;31mSystemExit\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "this is a sample text\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D." + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Program 16.3, Page number: 366" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "def main():\n", + "\n", + " #Variable Declaration/ User Input\n", + " print(\"Enter name of the file to be copied: \")\n", + " inName=\"source.txt\"\n", + " #inName=raw_input()\n", + "\n", + " print(\"Enter name of the output file: \")\n", + " outName=\"target.txt\"\n", + " #outName=raw_input()\n", + "\n", + " \n", + " try:\n", + " inn=open(inName,\"r\") \n", + " except:# Exception:\n", + " print(\"cant open {0} for reading\".format(inName))\n", + " sys.exit()\n", + "\n", + " try:\n", + " out=open(outName,\"w\") \n", + " except:# Exception:\n", + " print(\"cant open {0} for writing\".format(outName))\n", + " sys.exit()\n", + "\n", + " string=inn.read() #Read content from File-1\n", + " out.write(string) #Write content to File-2\n", + "\n", + " inn.close()\n", + " out.close()\n", + "\n", + " print(\"File has been copied.\\n\");\n", + "\n", + "if __name__=='__main__':\n", + " main()\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "SystemExit", + "evalue": "", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter name of the file to be copied: \n", + "Enter name of the output file: \n", + "cant open source.txt for reading\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Programming_in_C/Chapter_16.ipynb b/Programming_in_C/Chapter_16.ipynb index 2b519af8..535875b5 100755 --- a/Programming_in_C/Chapter_16.ipynb +++ b/Programming_in_C/Chapter_16.ipynb @@ -1,6 +1,6 @@ { "metadata": { - "name": "Chapter 16" + "name": "" }, "nbformat": 3, "nbformat_minor": 0, @@ -211,7 +211,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "\n", + "import sys\n", "def main():\n", "\n", " #Variable Declaration/ User Input\n", @@ -252,14 +252,12 @@ "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "global name 'source' is not defined", + "ename": "SystemExit", + "evalue": "", "output_type": "pyerr", "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m/home/jovina/TBC/nalin/Stephen G Kochan--Programming in C/\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 40\u001b[0m \u001b[1;31m#Setting top level conditional script\u001b[0m\n\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0m__name__\u001b[0m\u001b[1;33m==\u001b[0m\u001b[1;34m'__main__'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 42\u001b[1;33m \u001b[0mmain\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 43\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m/home/jovina/TBC/nalin/Stephen G Kochan--Programming in C/\u001b[0m in \u001b[0;36mmain\u001b[1;34m()\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[0minn\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msource\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtxt\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;32mexcept\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;31m# Exception:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"cant open {0} for reading\"\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msource\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtxt\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mNameError\u001b[0m: global name 'source' is not defined" + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[0;31mSystemExit\u001b[0m\n" ] }, { @@ -267,11 +265,19 @@ "stream": "stdout", "text": [ "Enter name of the file to be copied: \n", - "Enter name of the output file: \n" + "Enter name of the output file: \n", + "cant open source.txt for reading\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" ] } ], - "prompt_number": 3 + "prompt_number": 2 }, { "cell_type": "code", diff --git a/Schaum's_Outline/README.txt b/Schaum's_Outline/README.txt new file mode 100755 index 00000000..272f5329 --- /dev/null +++ b/Schaum's_Outline/README.txt @@ -0,0 +1,10 @@ +Contributed By: Hiren Shah +Course: mca +College/Institute/Organization: Financial Technology +Department/Designation: Developer +Book Title: Schaum's Outlines: Programming with C++ +Author: John R. Hubbard +Publisher: McGRAW-HILL +Year of publication: 2000 +Isbn: 0-07-135346-1. +Edition: 2nd \ No newline at end of file diff --git a/Schaum's_Outline/ch1.ipynb b/Schaum's_Outline/ch1.ipynb new file mode 100755 index 00000000..175e4501 --- /dev/null +++ b/Schaum's_Outline/ch1.ipynb @@ -0,0 +1,448 @@ +{ + "metadata": { + "name": "ch1" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1: Elementary C++ Programming" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, page no. 2" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello, World!\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello, World!\n", + "\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.2, page no. 3" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "print \"Hello, World!\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello, World!\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.3, page no. 4" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "print \"Hel\" + \"lo, Wo\" + \"rld!\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello, World!\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.4, page no. 5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "print \"Hello, W\" + 'o' + \"rld\" + '!' " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello, World!\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.5, page no. 5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "print \"The Millennium ends Dec %d %d \" %(31,2000)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The Millennium ends Dec 31 2000 \n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.6, page no. 5" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "m = 44 # assigns the value 44 to the variable m\n", + "print \"m = %d \" % m,\n", + "n = m + 33 # assigns the value 77 to the variable n\n", + "print \"and n = %d \" % n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "m = 44 and n = 77 \n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.7, page no. 6" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n=44\n", + "print \"n = %d\" % n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 44\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.8, page no. 7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Python does not have semicolons so wont give any errors.\n", + "n=44\n", + "print \"n = %d\" % n " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 44\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.9, page no. 7" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "m = 0 #In python we do not have declaration of variables, we just initialize it and use it.\n", + "n=44\n", + "print \"m = %d and n = %d\" %(m,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "m = 0 and n = 44\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.10, page no. 8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "BEEP = '\\b'\n", + "MAXINT = 2147483647\n", + "N = MAXINT/2\n", + "KM_PER_MI = 1.60934\n", + "PI = 3.14159265358979323846" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.11, page no. 8" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "print \"Enter two integers: \"\n", + "m = int(raw_input())\n", + "n = int(raw_input())\n", + "print \"m = %d , n = %d \" %(m,n)\n", + "\n", + "print \"Enter three decimal numbers: \"\n", + "x = float(raw_input())\n", + "y = float(raw_input())\n", + "z = float(raw_input())\n", + "\n", + "print \"x = %f , y = %f , z = %f\" %(x,y,z)\n", + "\n", + "print \"Enter four characters: \";\n", + "c1 = raw_input()\n", + "c2 = raw_input()\n", + "c3 = raw_input()\n", + "c4 = raw_input()\n", + "print \"c1 = \" + c1 + \", c2 = \" + c2 + \", c3 = \" + c3 + \", c4 = \" + c4 " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "m = 22 , n = 44 \n", + "Enter three decimal numbers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2.2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4.4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6.6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 2.200000 , y = 4.400000 , z = 6.600000\n", + "Enter four characters: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "A\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "B\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "C\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "D\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "c1 = A, c2 = B, c3 = C, c4 = D\n" + ] + } + ], + "prompt_number": 11 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch10.ipynb b/Schaum's_Outline/ch10.ipynb new file mode 100755 index 00000000..eb3d1761 --- /dev/null +++ b/Schaum's_Outline/ch10.ipynb @@ -0,0 +1,877 @@ +{ + "metadata": { + "name": "ch10" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 10: Classes" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.1, Page no: 233" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self):\n", + " self.num = 0\n", + " self.den = 0\n", + " def assign(self,n,d):\n", + " self.num = n\n", + " self.den = d\n", + " def convert(self):\n", + " return float(self.num)/self.den\n", + " def invert(self):\n", + " self.num,self.den = self.den,self.num\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + " \n", + "x = Ratio()\n", + "x.assign(22,7)\n", + "print \"x = \",\n", + "x.print_()\n", + "print \" = \" , x.convert() \n", + "x.invert()\n", + "print \"1/x = \",\n", + "x.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 22 / 7 = 3.14285714286\n", + "1/x = 7 / 22\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.2, Page no: 234" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self):\n", + " self.num = 0\n", + " self.den = 0\n", + " def assign(self,n,d):\n", + " self.num = n\n", + " self.den = d\n", + " def convert(self):\n", + " return float(self.num)/self.den\n", + " def invert(self):\n", + " self.num,self.den = self.den,self.num\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.3, Page no: 235" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n,d):\n", + " self.num = n\n", + " self.den = d\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + "x = Ratio(-1,3)\n", + "y = Ratio(22,7)\n", + "print \"x = \",\n", + "x.print_()\n", + "print \" and y = \",\n", + "y.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = -1 / 3 and y = 22 / 7\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.4, Page no: 236" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " if n==None:\n", + " self.num = 0\n", + " self.den = 1\n", + " elif d==None:\n", + " self.num = n\n", + " self.den = 1\n", + " else:\n", + " self.num = n\n", + " self.den = d\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + "x = Ratio()\n", + "y = Ratio(4)\n", + "z = Ratio(22,7)\n", + "print \"x = \",\n", + "x.print_()\n", + "print \"\\ny = \",\n", + "y.print_()\n", + "print \"\\nz = \",\n", + "z.print_()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 0 / 1 \n", + "y = 4 / 1 \n", + "z = 22 / 7\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.5, Page no: 237" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " if n==None:\n", + " self.num = 0\n", + " self.den = 1\n", + " elif d==None:\n", + " self.num = n\n", + " self.den = 1\n", + " else:\n", + " self.num = n\n", + " self.den = d\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.6, Page no: 237" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + "\n", + "x = Ratio()\n", + "y = Ratio(4)\n", + "z = Ratio(22,7)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.7, Page no: 238" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " def numerator(self):\n", + " return self.num\n", + " def denominator(self):\n", + " return self.den\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + "\n", + "x = Ratio(22,7)\n", + "print x.numerator() , '/' , x.denominator() " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "22 / 7\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.8, Page no: 238" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def numerator(self):\n", + " return self.num\n", + " def denominator(self):\n", + " return self.den\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(100,-360)\n", + "x.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "-5 / 18\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.9, Page no: 240" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=0,d=None):\n", + " if d == None:\n", + " self.num = n.num\n", + " self.den = n.den\n", + " else: \n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def numerator(self):\n", + " return self.num\n", + " def denominator(self):\n", + " return self.den\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(100,360)\n", + "y = Ratio(x)\n", + "print \"x = \",\n", + "x.print_()\n", + "print \"y = \",\n", + "y.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 5 / 18 y = 5 / 18\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.10, Page no: 241" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=0,d=None):\n", + " if d == None:\n", + " print \"COPY CONSTRUCTOR CALLED\"\n", + " self.num = n.num\n", + " self.den = n.den\n", + " else: \n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def numerator(self):\n", + " return self.num\n", + " def denominator(self):\n", + " return self.den\n", + " def print_(self):\n", + " print self.num , '/' , self.den ,\n", + "\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "def f(r):\n", + " s = Ratio(r)\n", + "\n", + "x = Ratio(22,7)\n", + "y = Ratio(x) #calls the copy constructor, copying x to y\n", + "f(y)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "COPY CONSTRUCTOR CALLED\n", + "COPY CONSTRUCTOR CALLED\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.11, Page no: 242" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python objects die when program gets exit.\n", + "'''\n", + "\n", + "class Ratio:\n", + " def __init__(self):\n", + " print \"OBJECT IS BORN.\"\n", + " def __del__(self):\n", + " print \"OBJECT DIES.\"\n", + "\n", + "x = Ratio()\n", + "print \"Now x is alive.\"\n", + "print \"Now between blocks.\"\n", + "y = Ratio()\n", + "print \"Now y is alive.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "OBJECT IS BORN.\n", + "Now x is alive.\n", + "Now between blocks.\n", + "OBJECT IS BORN.\n", + "Now y is alive.\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.12, Page no: 244" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class X:\n", + " def __init(self):\n", + " data = 0\n", + "\n", + "p = X()\n", + "p.data = 22\n", + "print \"p.data = \" , p.data , \" = \" , p.data\n", + "p.data = 44\n", + "print \" p.data = \" , p.data , \" = \" , p.data " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "p.data = 22 = 22\n", + " p.data = 44 = 44\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.13, Page no: 244" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Node:\n", + " def __init__(self,d,q=None):\n", + " self.data = d\n", + " self.next = q\n", + "\n", + "n = int(raw_input())\n", + "q = Node(n)\n", + "while True:\n", + " n = int(raw_input())\n", + " if n<=0:\n", + " break\n", + " p = Node(n, q)\n", + " q = p\n", + "k = p\n", + "while k != None:\n", + " print k.data , '->' , \n", + " k = k.next\n", + "print '*'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "66\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "77 -> 66 -> 55 -> 44 -> 33 -> 22 -> *\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.14, Page no: 246" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Python does not support static data type.\n", + "Python automatically handles local variable so we need not to delete it.\n", + "'''\n", + "count = 0\n", + "class Widget:\n", + " def __init__(self):\n", + " global count\n", + " count += 1\n", + " \n", + "w = Widget()\n", + "x = Widget()\n", + "print \"Now there are \" , count , 'widgets'\n", + "if True:\n", + " w = Widget()\n", + " x = Widget()\n", + " y = Widget()\n", + " z = Widget()\n", + " print \"Now there are\" , count , 'widgets' \n", + "print \"Now there are \" , count , 'widgets'\n", + "y = Widget()\n", + "print \"Now there are \" , count , 'widgets'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "OBJECT DIES.\n", + "Now there are 2 widgets\n", + "OBJECT DIES.\n", + "Now there are 6 widgets\n", + "Now there are 6 widgets\n", + "Now there are 7 widgets\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.15, Page no: 246" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "count = 0\n", + "class Widget:\n", + " def __init__(self):\n", + " global count\n", + " count += 1\n", + " def numWidgets(self):\n", + " global count\n", + " return count\n", + " \n", + "w = Widget()\n", + "x = Widget()\n", + "print \"Now there are \" , w.numWidgets() , 'widgets'\n", + "if True:\n", + " w = Widget()\n", + " x = Widget()\n", + " y = Widget()\n", + " z = Widget()\n", + " print \"Now there are\" , w.numWidgets() , 'widgets' \n", + "print \"Now there are \" , w.numWidgets() , 'widgets'\n", + "y = Widget()\n", + "print \"Now there are \" , w.numWidgets() , 'widgets'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Now there are 2 widgets\n", + "Now there are 6 widgets\n", + "Now there are 6 widgets\n", + "Now there are 7 widgets\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 10.16, Page no: 247" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "count = 0\n", + "class Widget:\n", + " def __init__(self):\n", + " global count\n", + " count += 1\n", + " def numWidgets(self):\n", + " global count\n", + " return count\n", + " \n", + "w = Widget()\n", + "x = Widget()\n", + "print \"Now there are \" , w.numWidgets() , 'widgets'\n", + "if True:\n", + " w = Widget()\n", + " x = Widget()\n", + " y = Widget()\n", + " z = Widget()\n", + " print \"Now there are\" , w.numWidgets() , 'widgets' \n", + "print \"Now there are \" , w.numWidgets() , 'widgets'\n", + "y = Widget()\n", + "print \"Now there are \" , w.numWidgets() , 'widgets'" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Now there are 2 widgets\n", + "Now there are 6 widgets\n", + "Now there are 6 widgets\n", + "Now there are 7 widgets\n" + ] + } + ], + "prompt_number": 18 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch11.ipynb b/Schaum's_Outline/ch11.ipynb new file mode 100755 index 00000000..321fb35b --- /dev/null +++ b/Schaum's_Outline/ch11.ipynb @@ -0,0 +1,793 @@ +{ + "metadata": { + "name": "ch11" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 11: Overloading Operators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.1, Page no: 256" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " if d==None:\n", + " self.num = n.num\n", + " self.den = n.den\n", + " elif n==None:\n", + " self.num = 0\n", + " self.den = 1\n", + " else:\n", + " self.num = n\n", + " self.den = d\n", + " \n", + " def equals(self):\n", + " return self # retuns calling object." + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.2, Page no: 257" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " pass\n", + " \n", + " def equals(self):\n", + " pass\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.3, Page no: 256" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " if d==None:\n", + " self.num = n.num\n", + " self.den = n.den\n", + " elif n==None:\n", + " self.num = 0\n", + " self.den = 1\n", + " else:\n", + " self.num = n\n", + " self.den = d\n", + " \n", + "\n", + "z = Ratio(22,7)\n", + "y = z\n", + "x = z\n", + "\n", + "x = Ratio(22,7)\n", + "y = Ratio(x)\n", + "z = x\n", + "w = x" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.4, Page no: 259" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " self.num = n\n", + " self.den = d\n", + " def __mul__(self,y):\n", + " pass\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.5, Page no: 259" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "x = Ratio(22,7)\n", + "y = Ratio(-3,8)\n", + "z = x\n", + "z.print_()\n", + "x = y*z\n", + "x.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "22 / 7\n", + "-33 / 28\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.6, Page no: 260" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __imul__(self,y):\n", + " self.num = self.num * y.num\n", + " self.den = self.den * y.den\n", + " def print_(self):\n", + " print self.num , '/', self.den" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.7, Page no: 260" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __imul__(self,y):\n", + " self.num = self.num * y.num\n", + " self.den = self.den * y.den\n", + " def __eq__(self,y):\n", + " return (x.num * y.den == y.num * x.den)\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.8, Page no: 261" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "''' \n", + "Python does not use << operator for printing. So here we are just declaring function name as print_.\n", + "'''\n", + "\n", + "class Ratio:\n", + " def __init__(self,n=None,d=None):\n", + " self.num = n\n", + " self.den = d\n", + " def __imul__(self,y):\n", + " self.num = self.num * y.num\n", + " self.den = self.den * y.den\n", + " def __eq__(self,y):\n", + " return (x.num * y.den == y.num * x.den)\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + "\n", + "\n", + "x = Ratio(22,7)\n", + "y = Ratio(-3,8)\n", + "x.print_() , y.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "22 / 7\n", + "-3 / 8\n" + ] + }, + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 8, + "text": [ + "(None, None)" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.9, Page no: 262" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Python does not have >> for input. so we will use input function.\n", + "'''\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def input(self):\n", + " self.num = int(raw_input('Numerator : '))\n", + " self.den = int(raw_input('Denominator : '))\n", + " self.reduce()\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "\n", + "x = Ratio()\n", + "y = Ratio()\n", + "x.input()\n", + "y.input()\n", + "x.print_()\n", + "y.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Numerator : -10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Denominator : -24\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Numerator : 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Denominator : -20\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 / 12\n", + "-9 / 5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.10, Page no: 263" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def input(self):\n", + " self.num = int(raw_input('Numerator : '))\n", + " self.den = int(raw_input('Denominator : '))\n", + " self.reduce()\n", + " def __float__(self):\n", + " return float(self.num)/self.den\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 15.py\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(-5,8)\n", + "print \"x = \" , \n", + "x.print_() \n", + "print \", float(x) = \" , float(x) \n", + "P = Ratio(22,7)\n", + "PI = float(P)\n", + "print \"P = \" ,\n", + "P.print_() \n", + "print \", PI = \" , PI\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = -5 / 8\n", + ", float(x) = -0.625\n", + "P = 22 / 7\n", + ", PI = 3.14285714286\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.11, Page no: 264" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def __iadd__(self,n):\n", + " self.num += self.den\n", + " return self\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(22,7)\n", + "x += 1\n", + "y = x\n", + "print \"y = \" ,\n", + "y.print_()\n", + "print \", x = \",\n", + "x.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y = 29 / 7\n", + ", x = 29 / 7\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.12, Page no: 265" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def __iadd__(self,n):\n", + " self.num += self.den\n", + " return self\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(22,7)\n", + "y = Ratio(x.num,x.den)\n", + "x += 1\n", + "print \"y = \" ,\n", + "y.print_()\n", + "print \", x = \",\n", + "x.print_()\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "y = 22 / 7\n", + ", x = 29 / 7\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 11.13, Page no:266" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def gcd(m,n):\n", + " # returns the greatest common divisor of m and n:\n", + " if (m0):\n", + " r = m % n\n", + " m = n\n", + " n = r\n", + " return m\n", + "class Ratio:\n", + " def __init__(self,n=0,d=1):\n", + " self.num = n\n", + " self.den = d\n", + " self.reduce()\n", + " def __mul__(self,y):\n", + " z = Ratio(self.num * y.num, self.den * y.den)\n", + " return z\n", + " def print_(self):\n", + " print self.num , '/', self.den\n", + " \n", + " def __getitem__(self,k):\n", + " if k == 1:\n", + " return self.num\n", + " else:\n", + " return self.den\n", + " def reduce(self):\n", + " # enforce invariant(den > 0):\n", + " if (self.num == 0 or self.den == 0):\n", + " self.num = 0\n", + " self.den = 1\n", + " return\n", + " if (self.den < 0):\n", + " self.den *= -1\n", + " self.num *= -1\n", + " # enforce invariant(gcd(num,den) == 1):\n", + " if (self.den == 1):\n", + " return\n", + " # it's already reduced\n", + " sgn = 0\n", + " if self.num < 0:\n", + " sgn = -1\n", + " else:\n", + " sgn = 1\n", + " g = gcd(sgn*self.num,self.den)\n", + " self.num /= g\n", + " self.den /= g\n", + "\n", + "x = Ratio(22,7)\n", + "print \"x = \" ,\n", + "x.print_()\n", + "print \"x[1] = \" , x[1] , \", x[2] = \" , x[2]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 22 / 7\n", + "x[1] = 22 , x[2] = 7\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch12.ipynb b/Schaum's_Outline/ch12.ipynb new file mode 100755 index 00000000..2743b6a5 --- /dev/null +++ b/Schaum's_Outline/ch12.ipynb @@ -0,0 +1,869 @@ +{ + "metadata": { + "name": "ch12" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 12: Composition and Inheritance" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.1, Page no: 273" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Person:\n", + " def __init__(self,n=\"\",nat=\"U.S.A.\",s=1):\n", + " self.name = n\n", + " self.nationality = nat\n", + " self.sex = s\n", + "\n", + " def printName(self):\n", + " print self.name,\n", + " \n", + " def printNationality(self):\n", + " print self.nationality,\n", + "\n", + "creator = Person(\"Bjarne Stroustrup\", \"Denmark\")\n", + "print \"The creator of C++ was \" ,\n", + "creator.printName() \n", + "print \", who was born in \" ,\n", + "creator.printNationality() \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The creator of C++ was Bjarne Stroustrup , who was born in Denmark\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.2, Page no: 274" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Date:\n", + " def __init__(self,m=0,d=0,y=0):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " \n", + " def setDate(self,m,d,y):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " # Python doesn't have >> operator for input so we are just using input function\n", + " def input(self):\n", + " self.month = int(raw_input()) \n", + " self.day = int(raw_input())\n", + " self.year = int(raw_input()) \n", + " \n", + " # Python doesn't have << operator for output so we are just using print function\n", + " def print_(self):\n", + " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", + " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", + " \"December\"]\n", + " print monthName[self.month] , self.day , \",\" , self.year\n", + "\n", + "peace = Date(11,11,1918)\n", + "print \"World War I ended on \" ,\n", + "peace.print_()\n", + "peace.setDate(8,14,1945)\n", + "print \"World War II ended on \" ,\n", + "peace.print_()\n", + "print \"Enter month, day, and year: \"\n", + "date = Date()\n", + "date.input()\n", + "print \"The date is \" , \n", + "date.print_()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "World War I ended on November 11 , 1918\n", + "World War II ended on August 14 , 1945\n", + "Enter month, day, and year: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1976\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The date is July 4 , 1976\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.3, Page no: 274" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Date:\n", + " def __init__(self,m=0,d=0,y=0):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " \n", + " def setDate(self,m,d,y):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " # Python doesn't have >> operator for input so we are just using input function\n", + " def input(self):\n", + " self.month = int(raw_input()) \n", + " self.day = int(raw_input())\n", + " self.year = int(raw_input()) \n", + " \n", + " # Python doesn't have << operator for output so we are just using print function\n", + " def print_(self):\n", + " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", + " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", + " \"December\"]\n", + " print monthName[self.month] , self.day , \",\" , self.year\n", + "\n", + "class Person:\n", + " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", + " self.name = n\n", + " self.nationality = nat\n", + " self.sex = s\n", + " self.dob = Date()\n", + " self.dod = Date()\n", + " def setDOB(self,m,d,y):\n", + " self.dob.setDate(m,d,y)\n", + " def setDOD(self,m,d,y):\n", + " self.dod.setDate(m,d,y)\n", + " def printName(self):\n", + " print self.name,\n", + " def printNationality(self):\n", + " print self.nationality,\n", + " def printDOB(self):\n", + " self.dob.print_()\n", + " def printDOD(self):\n", + " self.dod.print_()\n", + "\n", + "author = Person(\"Thomas Jefferson\", 1)\n", + "author.setDOB(4,13,1743)\n", + "author.setDOD(7,4,1826)\n", + "print \"The author of the Declaration of Independence was \",\n", + "author.printName()\n", + "print \".\\nHe was born on \",\n", + "author.printDOB()\n", + "print \" and died on \",\n", + "author.printDOD()\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The author of the Declaration of Independence was Thomas Jefferson .\n", + "He was born on April 13 , 1743\n", + " and died on July 4 , 1826\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.4, Page no: 276" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Date:\n", + " def __init__(self,m=0,d=0,y=0):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " \n", + " def setDate(self,m,d,y):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " # Python doesn't have >> operator for input so we are just using input function\n", + " def input(self):\n", + " self.month = int(raw_input()) \n", + " self.day = int(raw_input())\n", + " self.year = int(raw_input()) \n", + " \n", + " # Python doesn't have << operator for output so we are just using print function\n", + " def print_(self):\n", + " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", + " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", + " \"December\"]\n", + " print monthName[self.month] , self.day , \",\" , self.year\n", + "\n", + "class Person:\n", + " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", + " self.name = n\n", + " self.nationality = nat\n", + " self.sex = s\n", + " self.dob = Date()\n", + " self.dod = Date()\n", + " def setDOB(self,m,d,y):\n", + " self.dob.setDate(m,d,y)\n", + " def setDOD(self,m,d,y):\n", + " self.dod.setDate(m,d,y)\n", + " def printName(self):\n", + " print self.name,\n", + " def printNationality(self):\n", + " print self.nationality,\n", + " def printDOB(self):\n", + " self.dob.print_()\n", + " def printDOD(self):\n", + " self.dod.print_()\n", + "\n", + "class Student(Person):\n", + " def __init__(self,n,s=0,i=\"\"):\n", + " Person.__init__(self,n,s)\n", + " self.id = i\n", + " self.credits = 0\n", + " self.gpa = 0\n", + " self.dom = Date()\n", + "\n", + " def setDOM(self,m,d,y):\n", + " self.dom.setDate(m, d, y)\n", + " def printDOM(self):\n", + " self.dom.print_()\n", + "\n", + "x = Student(\"Ann Jones\", 0, \"219360061\")\n", + "x.setDOB(5, 13, 1977)\n", + "x.setDOM(8, 29, 1995)\n", + "x.printName()\n", + "print \"\\n\\t Born: \" ,\n", + "x.printDOB()\n", + "print \"\\n\\tMatriculated: \",\n", + "x.printDOM()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ann Jones \n", + "\t Born: May 13 , 1977\n", + "\n", + "\tMatriculated: August 29 , 1995\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.5, Page no: 276" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Date:\n", + " def __init__(self,m=0,d=0,y=0):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " \n", + " def setDate(self,m,d,y):\n", + " self.month = m\n", + " self.day = d\n", + " self.year = y\n", + " # Python doesn't have >> operator for input so we are just using input function\n", + " def input(self):\n", + " self.month = int(raw_input()) \n", + " self.day = int(raw_input())\n", + " self.year = int(raw_input()) \n", + " \n", + " # Python doesn't have << operator for output so we are just using print function\n", + " def print_(self):\n", + " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", + " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", + " \"December\"]\n", + " print monthName[self.month] , self.day , \",\" , self.year\n", + "\n", + "class Person:\n", + " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", + " self.name = n\n", + " self.nationality = nat\n", + " self.sex = s\n", + " self.dob = Date()\n", + " self.dod = Date()\n", + " def setDOB(self,m,d,y):\n", + " self.dob.setDate(m,d,y)\n", + " def setDOD(self,m,d,y):\n", + " self.dod.setDate(m,d,y)\n", + " def printName(self):\n", + " print self.name,\n", + " def printNationality(self):\n", + " print self.nationality,\n", + " def printDOB(self):\n", + " self.dob.print_()\n", + " def printDOD(self):\n", + " self.dod.print_()\n", + "\n", + "class Student(Person):\n", + " def __init__(self,n,s=0,i=\"\"):\n", + " Person.__init__(self,n,s)\n", + " self.id = i\n", + " self.credits = 0\n", + " self.gpa = 0\n", + " self.dom = Date()\n", + "\n", + " def setDOM(self,m,d,y):\n", + " self.dom.setDate(m, d, y)\n", + " def printDOM(self):\n", + " self.dom.print_()\n", + " def printSex(self):\n", + " if self.sex == 1:\n", + " print \"male\"\n", + " else:\n", + " print 'female'\n", + "\n", + "x = Student(\"Ann Jones\", 0, \"219360061\")\n", + "x.setDOB(5, 13, 1977)\n", + "x.setDOM(8, 29, 1995)\n", + "x.setDOD(7,4,1826)\n", + "x.printName()\n", + "print \"\\n\\t Born: \" , \n", + "x.printDOB()\n", + "print \"\\n\\t Sex: \" ,\n", + "x.printSex()\n", + "print \"\\n\\tMatriculated: \",\n", + "x.printDOM()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ann Jones \n", + "\t Born: May 13 , 1977\n", + "\n", + "\t Sex: female\n", + "\n", + "\tMatriculated: August 29 , 1995\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.6, Page no: 279" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class X:\n", + " def __init__(self):\n", + " self.a = 0\n", + " def f(self):\n", + " print \"X::f() executing\"\n", + "class Y(X):\n", + " def __init__(self):\n", + " self.a = 0\n", + " def f(self):\n", + " print \"Y::f() executing\"\n", + "x = X()\n", + "x.a = 22\n", + "x.f()\n", + "print \"x.a = \" , x.a\n", + "y = Y()\n", + "y.a = 44\n", + "# assigns 44 to the a defined in Y\n", + "y._X__a = 66\n", + "# assigns 66 to the a defined in X\n", + "y.f()\n", + "# invokes the f() defined in Y\n", + "X.f(x)\n", + "# invokes the f() defined in X\n", + "print \"y.a = \" , y.a \n", + "print \"y._X__a = \" , y._X__a \n", + "z = y\n", + "print \"z.a = \" , z._X__a \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "X::f() executing\n", + "x.a = 22\n", + "Y::f() executing\n", + "X::f() executing\n", + "y.a = 44\n", + "y._X__a = 66\n", + "z.a = 66\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.7, Page no: 280" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python destuctor is called when program goes exit. So output may be differ than c.\n", + "'''\n", + "class X:\n", + " def __init__(self):\n", + " print \"X::X() constructor executing \"\n", + " def __del__(self):\n", + " print \"X::X() destructor executing \"\n", + "\n", + "class Y(X):\n", + " def __init__(self):\n", + " X.__init__(self)\n", + " print \"Y::Y() constructor executing \"\n", + " def __del__(self):\n", + " print \"Y::Y() destructor executing \"\n", + "\n", + "class Z(Y):\n", + " def __init__(self,i):\n", + " Y.__init__(self)\n", + " print \"Z::Z(\" , i , \") constructor executing \"\n", + " def __del__(self):\n", + " print \"Z::Z() destructor executing \"\n", + " \n", + "\n", + "Z = Z(44)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "X::X() constructor executing \n", + "Y::Y() constructor executing \n", + "Z::Z( 44 ) constructor executing \n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.8, Page no: 281" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python destuctor is called when program goes exit. So output may be differ than c.\n", + "'''\n", + "class Person:\n", + " def __init__(self,s):\n", + " self.name = s\n", + " def __del__(self):\n", + " pass\n", + "\n", + "class Student(Person):\n", + " def __init__(self,s,m):\n", + " Person.__init__(self,s)\n", + " self.major = m\n", + " def __del__(self):\n", + " pass\n", + "x = Person(\"Bob\")\n", + "y = Student(\"Sarah\", \"Biology\")\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.9, Page no: 282" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Person:\n", + " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", + " self.name = n\n", + " self.nationality = nat\n", + " self.sex = s\n", + " self.dob = Date()\n", + " self.dod = Date()\n", + " def setDOB(self,m,d,y):\n", + " self.dob.setDate(m,d,y)\n", + " def setDOD(self,m,d,y):\n", + " self.dod.setDate(m,d,y)\n", + " def printName(self):\n", + " print self.name,\n", + " def printNationality(self):\n", + " print self.nationality,\n", + " def printDOB(self):\n", + " self.dob.print_()\n", + " def printDOD(self):\n", + " self.dod.print_()\n", + " def setHSgraduate(self,g):\n", + " self.hs = g\n", + " def isHSgraduate(self):\n", + " return hs\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.10, Page no: 283" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : By default all methods in python are virtual. so output would be differ than c.\n", + "'''\n", + "class X:\n", + " def f(self):\n", + " print \"X::f() executing\"\n", + "class Y(X):\n", + " def f(self):\n", + " print \"Y::f() executing\"\n", + "x = X()\n", + "y = Y()\n", + "p = x\n", + "p.f()\n", + "p = y\n", + "p.f()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "X::f() executing\n", + "Y::f() executing\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.11, Page no: 284" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Person:\n", + " def __init__(self,n):\n", + " self.name = n\n", + " def print_(self):\n", + " print 'My name is' , self.name\n", + "\n", + "class Student(Person):\n", + " def __init__(self,s,g):\n", + " Person.__init__(self,s)\n", + " self.gpa = g\n", + " def print_(self):\n", + " print 'My name is ',self.name, ' and my G.P.A. is', self.gpa\n", + "\n", + "class Professor(Person):\n", + " def __init__(self,s,n):\n", + " Person.__init__(self,s)\n", + " self.publs = n\n", + " def print_(self):\n", + " print 'My name is ', self.name,' and i have ' , self.publs,' publications.'\n", + "\n", + "x = Person(\"Bob\")\n", + "p = x\n", + "p.print_()\n", + "y = Student(\"Tom\", 3.47)\n", + "p = y\n", + "p.print_()\n", + "z = Professor(\"Ann\", 7)\n", + "p = z\n", + "p.print_()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "My name is Bob\n", + "My name is Tom and my G.P.A. is 3.47\n", + "My name is Ann and i have 7 publications.\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.12, Page no: 285" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "This program is similar to Example 12.6:\n", + "'''\n", + "class X:\n", + " def __init__(self):\n", + " self.p = [0,0]\n", + " print 'X().',\n", + " def __del__(self):\n", + " print '~X().'\n", + "\n", + "class Y(X):\n", + " def __init__(self):\n", + " X.__init__(self)\n", + " self.q = []\n", + " for i in range(1023):\n", + " self.q.append(0)\n", + " print 'Y() : Y::q = ', hex(id(self.q)) ,'.',\n", + " def __del__(self):\n", + " print '~Y().'\n", + "\n", + "for i in range(8):\n", + " r = Y()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", + "X(). Y() : Y::q = 0x90c944c . ~Y().\n", + "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", + "X(). Y() : Y::q = 0x90c944c . ~Y().\n", + "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", + "X(). Y() : Y::q = 0x90c944c . ~Y().\n", + "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", + "X(). Y() : Y::q = 0x90c944c . ~Y().\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 12.13, Page no: 288" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Media:\n", + " def __init__(self):\n", + " self.title = ''\n", + " def print_(self):\n", + " pass\n", + " def id(self):\n", + " pass\n", + "\n", + "class Book(Media):\n", + " def __init__(self,a='',t=\"\",p=\"\",i=\"\"):\n", + " self.author = a\n", + " self.publisher = p\n", + " self.isbn = i\n", + " self.title = t\n", + " def print_(self):\n", + " print self.title , \" by \" , self.author\n", + " def id(self):\n", + " return self.isbn\n", + "\n", + "class CD(Media):\n", + " def __init__(self,t=\"\",c=\"\",m=\"\",n=\"\"):\n", + " self.composer = c\n", + " self.make = m\n", + " self.number = n\n", + " self.title = t\n", + " def print_(self):\n", + " print self.title , \", \" , self.composer\n", + " def id(self):\n", + " s = str(self.make) + ' ' + str(self.number)\n", + " return s\n", + "\n", + "class Magazine(Media):\n", + " def __init__(self,t=\"\",i=\"\",v=0, n=0):\n", + " self.issn = i\n", + " self.volume = v\n", + " self.number = n\n", + " self.title = t\n", + " def print_(self):\n", + " print self.title , \" Magazine, Vol. \", self.volume , \", No.\" , self.number\n", + " def id(self):\n", + " return self.issn\n", + "\n", + "book = Book(\"Bjarne Stroustrup\", \"The C++ Programming Language\",\"Addison-Wesley\", \"0-201-53992-6\")\n", + "magazine = Magazine(\"TIME\", \"0040-781X\", 145, 23)\n", + "cd = CD(\"BACH CANTATAS\", \"Johann Sebastian Bach\",\"ARCHIV\", \"D120541\")\n", + "book.print_()\n", + "print \"\\tid: \" , book.id() \n", + "magazine.print_()\n", + "print \"\\tid: \" , magazine.id() \n", + "cd.print_()\n", + "print \"\\tid: \" , cd.id()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The C++ Programming Language by Bjarne Stroustrup\n", + "\tid: 0-201-53992-6\n", + "TIME Magazine, Vol. 145 , No. 23\n", + "\tid: 0040-781X\n", + "BACH CANTATAS , Johann Sebastian Bach\n", + "\tid: ARCHIV D120541\n" + ] + } + ], + "prompt_number": 14 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch13.ipynb b/Schaum's_Outline/ch13.ipynb new file mode 100755 index 00000000..eea108dd --- /dev/null +++ b/Schaum's_Outline/ch13.ipynb @@ -0,0 +1,426 @@ +{ + "metadata": { + "name": "ch13" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 13: Templates and Iterators" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.1, Page no: 300" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def swap(x,y):\n", + " x[0],y[0] = y[0],x[0]\n", + "\n", + "m = [22]\n", + "n = [66]\n", + "swap(m, n)\n", + "s1 = [\"John Adams\"]\n", + "s2 = [\"James Madison\"]\n", + "swap(s1, s2)\n", + "x = [22/7]\n", + "y = [-3]\n", + "swap(x, y)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.2, Page no: 301" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def sort(v,n):\n", + " for i in range(1,n):\n", + " for j in range(n-i):\n", + " if v[j] > v[j+1]:\n", + " v[j],v[j+1] = v[j+1],v[j]\n", + "\n", + "def print_( v,n):\n", + " for i in range(n):\n", + " print v[i],\n", + " print \"\"\n", + " \n", + "a = [55, 33, 88, 11, 44, 99, 77, 22, 66]\n", + "print_(a,9);\n", + "sort(a,9)\n", + "print_(a,9)\n", + "s = [\"Tom\", \"Hal\", \"Dan\", \"Bob\", \"Sue\", \"Ann\", \"Gus\"]\n", + "print_(s,7)\n", + "sort(s,7)\n", + "print_(s,7)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "55 33 88 11 44 99 77 22 66 \n", + "11 22 33 44 55 66 77 88 99 \n", + "Tom Hal Dan Bob Sue Ann Gus \n", + "Ann Bob Dan Gus Hal Sue Tom \n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.3, Page no: 303" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Stack:\n", + " def __init__(self,s=100):\n", + " self.size = s\n", + " self.top = -1\n", + " self.data = []\n", + " def push(self,x):\n", + " self.data.append( x)\n", + " self.top += 1\n", + " def pop(self):\n", + " d = self.data[self.top]\n", + " self.data.pop(self.top)\n", + " self.top -= 1\n", + " return d \n", + " def isEmpty(self):\n", + " return self.top == -1\n", + " def isFull(self):\n", + " return self.top==self.size-1\n", + " \n", + "intStack1 = Stack(5)\n", + "intStack2 = Stack(10)\n", + "charStack = Stack(8)\n", + "intStack1.push(77)\n", + "charStack.push('A')\n", + "intStack2.push(22)\n", + "charStack.push('E')\n", + "charStack.push('K')\n", + "intStack2.push(44)\n", + "print intStack2.pop() \n", + "print intStack2.pop() \n", + "if (intStack2.isEmpty()):\n", + " print \"intStack2 is empty.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n", + "22\n", + "intStack2 is empty.\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.4, Page no: 305" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "= operator does work in python by defaultly.\n", + "'''\n", + "class Vector:\n", + " def __init__(self,n=None):\n", + " if type(n) == int :\n", + " self.size = n\n", + " self.data = []\n", + " else:\n", + " self.size = 8\n", + " self.data = []\n", + " for i in range(self.size):\n", + " self.data.append(0)\n", + "v = Vector()\n", + "v.data[5] = 127\n", + "w = v\n", + "x = Vector(3)\n", + "print w.size\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.5, Page no: 306" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Vector:\n", + " def __init__(self,n=None):\n", + " if type(n) == int :\n", + " self.size = n\n", + " self.data = []\n", + " else:\n", + " self.size = 8\n", + " self.data = []\n", + " for i in range(self.size):\n", + " self.data.append(0)\n", + "\n", + "class Array(Vector):\n", + " def __init__(self,i,j):\n", + " Vector.__init__(self,j-i+1)\n", + " self.i0= i\n", + " def __setitem__(self,k,v):\n", + " self.data[k-self.i0] = v\n", + " def __getitem__(self,i):\n", + " return self.data[self.i0-i]\n", + " def firstSubscript(self):\n", + " return self.i0\n", + " def lastSubscript(self):\n", + " return self.i0+self.size-1\n", + "\n", + "x = Array(1,3)\n", + "x.data[0] = 3.14159\n", + "x.data[1] = 0.08516\n", + "x.data[2] = 5041.92\n", + "print \"x.size() = \" , x.size \n", + "print \"x.firstSubscript() = \" , x.firstSubscript() \n", + "print \"x.lastSubscript() = \" , x.lastSubscript()\n", + "for i in range(0,3):\n", + " print \"x[\" , i + 1 , \"] = \" , x.data[i]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x.size() = 3\n", + "x.firstSubscript() = 1\n", + "x.lastSubscript() = 3\n", + "x[ 1 ] = 3.14159\n", + "x[ 2 ] = 0.08516\n", + "x[ 3 ] = 5041.92\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.6, Page no: 308" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Matrix:\n", + " def __init__(self,r=1,c=1):\n", + " self.rows = r\n", + " self.columns = c\n", + " self.vector = []\n", + " for i in range(r):\n", + " a = []\n", + " for j in range(c):\n", + " a.append(0)\n", + " self.vector.append(a)\n", + "\n", + "a = Matrix(2,3)\n", + "a.vector[0][0] = 0.0\n", + "a.vector[0][1] = 0.1\n", + "a.vector[0][2] = 0.2\n", + "a.vector[1][0] = 1.0\n", + "a.vector[1][1] = 1.1\n", + "a.vector[1][2] = 1.2\n", + "\n", + "print \"The matrix a has \" , a.rows , \" rows and \", a.columns , \" columns:\"\n", + "for i in range(2):\n", + " for j in range(3):\n", + " print a.vector[i][j] ,\n", + " print \"\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The matrix a has 2 rows and 3 columns:\n", + "0.0 0.1 0.2 \n", + "1.0 1.1 1.2 \n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.7, Page no: 309" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "friends = []\n", + "\n", + "\n", + "friends.insert(0,\"Bowen, Van\")\n", + "friends.insert(0,\"Dixon, Tom\")\n", + "friends.insert(0,\"Mason, Joe\")\n", + "friends.insert(0,\"White, Ann\")\n", + "\n", + "for i in range(len(friends)):\n", + " print friends[i], '->' ,\n", + "print '*'\n", + "friends.remove('White, Ann')\n", + "print \"Removed: \" , 'White, Ann'\n", + "for i in range(len(friends)):\n", + " print friends[i], '->' ,\n", + "print '*'\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "White, Ann -> Mason, Joe -> Dixon, Tom -> Bowen, Van -> *\n", + "Removed: White, Ann\n", + "Mason, Joe -> Dixon, Tom -> Bowen, Van -> *\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 13.8, Page no: 313" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "friends = []\n", + "friends.append(\"Bowen, Van\")\n", + "friends.append(\"Dixon, Tom\")\n", + "friends.append(\"Mason, Joe\")\n", + "friends.append(\"White, Ann\")\n", + "for i in range(len(friends)):\n", + " print friends[i], '->' ,\n", + "print '*'\n", + "\n", + "friends.remove(\"Mason, Joe\")\n", + "friends[1] = \"Davis, Jim\"\n", + "for i in range(len(friends)):\n", + " print friends[i], '->' ,\n", + "print '*'\n", + "\n", + "friends.insert(2,\"Morse, Sam\")\n", + "for i in range(len(friends)):\n", + " print friends[i], '->' ,\n", + "print '*'\n", + "\n", + "for i in range(len(friends)):\n", + " print \"[\" ,friends[i] , \"]\" , '->' ,\n", + "print '*'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Bowen, Van -> Dixon, Tom -> Mason, Joe -> White, Ann -> *\n", + "Bowen, Van -> Davis, Jim -> White, Ann -> *\n", + "Bowen, Van -> Davis, Jim -> Morse, Sam -> White, Ann -> *\n", + "[ Bowen, Van ] -> [ Davis, Jim ] -> [ Morse, Sam ] -> [ White, Ann ] -> *\n" + ] + } + ], + "prompt_number": 8 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch14.ipynb b/Schaum's_Outline/ch14.ipynb new file mode 100755 index 00000000..457669dc --- /dev/null +++ b/Schaum's_Outline/ch14.ipynb @@ -0,0 +1,616 @@ +{ + "metadata": { + "name": "ch14" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 14: Standard C++ Vectors" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.1, Page no: 324" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.2, Page no: 325" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.3, Page no: 326" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in range(len(v)):\n", + " print v[i]\n", + "\n", + "v = []\n", + "load(v)\n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.4, Page no: 326" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "v.sort()\n", + "print_(v)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chile\n", + "Egypt\n", + "Italy\n", + "Japan\n", + "Kenya\n", + "Nepal\n", + "Spain\n", + "Zaire\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.5, Page no: 327" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "w = v\n", + "print_(v)\n", + "print_(w)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n", + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.6, Page no: 327" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "v.sort()\n", + "print_(v)\n", + "print \"v.front() = \" + v[0]\n", + "print \"v.back() = \" + v.pop(-1) \n", + "print \"v.back() = \" + v.pop(-1) \n", + "print \"v.back() = \" + v[-1] \n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chile\n", + "Egypt\n", + "Italy\n", + "Japan\n", + "Kenya\n", + "Nepal\n", + "Spain\n", + "Zaire\n", + "v.front() = Chile\n", + "v.back() = Zaire\n", + "v.back() = Spain\n", + "v.back() = Nepal\n", + "Chile\n", + "Egypt\n", + "Italy\n", + "Japan\n", + "Kenya\n", + "Nepal\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.7, Page no: 328" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "v.sort()\n", + "print_(v)\n", + "v.pop(2) # removes Italy\n", + "v.pop(-2) # removes Spain\n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chile\n", + "Egypt\n", + "Italy\n", + "Japan\n", + "Kenya\n", + "Nepal\n", + "Spain\n", + "Zaire\n", + "Chile\n", + "Egypt\n", + "Japan\n", + "Kenya\n", + "Nepal\n", + "Zaire\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.8, Page no: 329" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "v = []\n", + "load(v)\n", + "v.sort()\n", + "print_(v)\n", + "r = []\n", + "for i in range(2,len(v)-2):\n", + " r.append(v[i]) #removes the segment Italy..Nepal\n", + " \n", + "for i in r:\n", + " v.remove(i)\n", + "print_(v)\n", + "v.insert(2,\"India\")\n", + "print_(v)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chile\n", + "Egypt\n", + "Italy\n", + "Japan\n", + "Kenya\n", + "Nepal\n", + "Spain\n", + "Zaire\n", + "Chile\n", + "Egypt\n", + "Spain\n", + "Zaire\n", + "Chile\n", + "Egypt\n", + "India\n", + "Spain\n", + "Zaire\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.9, Page no: 329" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def load(v):\n", + " v.append(\"Japan\")\n", + " v.append(\"Italy\")\n", + " v.append(\"Spain\")\n", + " v.append(\"Egypt\")\n", + " v.append(\"Chile\")\n", + " v.append(\"Zaire\")\n", + " v.append(\"Nepal\")\n", + " v.append(\"Kenya\")\n", + " v.append(\"India\")\n", + " v.append(\"China\")\n", + " v.append(\"Malta\")\n", + " v.append(\"Syria\")\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i\n", + "\n", + "v = []\n", + "load(v)\n", + "print_(v)\n", + "egypt = v.index('Egypt')\n", + "malta = v.index('Malta')\n", + "w = v[egypt:malta+1]\n", + "w.sort()\n", + "print_(w)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Japan\n", + "Italy\n", + "Spain\n", + "Egypt\n", + "Chile\n", + "Zaire\n", + "Nepal\n", + "Kenya\n", + "India\n", + "China\n", + "Malta\n", + "Syria\n", + "Chile\n", + "China\n", + "Egypt\n", + "India\n", + "Kenya\n", + "Malta\n", + "Nepal\n", + "Zaire\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 14.10, Page no: 329" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def copy(v,x,n):\n", + " for i in x:\n", + " v.append(i)\n", + "\n", + "def projection(v,b):\n", + " v_size = len(v)\n", + " w = []\n", + " for i in range(0,v_size):\n", + " if b[i]:\n", + " w.append(v[i])\n", + " return w\n", + "\n", + "def print_(v):\n", + " for i in v:\n", + " print i,\n", + " print ''\n", + "\n", + "x = [ 22.2, 33.3, 44.4, 55.5, 66.6, 77.7, 88.8, 99.9 ]\n", + "v = []\n", + "copy(v, x, 8)\n", + "y = [ False, True, False, True, True, True, False, True ]\n", + "b = []\n", + "copy(b, y, 8)\n", + "w = projection(v, b)\n", + "print_(v)\n", + "print_(w)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "22.2 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n", + "33.3 55.5 66.6 77.7 99.9 \n" + ] + } + ], + "prompt_number": 10 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch2.ipynb b/Schaum's_Outline/ch2.ipynb new file mode 100755 index 00000000..8697f28c --- /dev/null +++ b/Schaum's_Outline/ch2.ipynb @@ -0,0 +1,740 @@ +{ + "metadata": { + "name": "ch2" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Chapter 2: Fundamental Types" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.1, page no. 17" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "flag=False\n", + "print \"flag = %r\" % flag\n", + "flag = True\n", + "print \"flag = %r\" % flag" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "flag = False\n", + "flag = True\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.2, page no. 19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "c='A'\n", + "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", + "c='t'\n", + "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", + "c='\\t' # the tab character\n", + "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", + "c='!'\n", + "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "c = A, int(c) = 65\n", + "c = t, int(c) = 116\n", + "c = \t, int(c) = 9\n", + "c = !, int(c) = 33\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.3, page no. 19" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "# defines the constants SHRT_MIN, etc.\n", + "print 'maximum limit int : ',\n", + "print sys.maxint\n", + "print 'float info'\n", + "print sys.float_info" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "maximum limit int : 2147483647\n", + "float info\n", + "sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.4, page no. 21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "m=54\n", + "n=20\n", + "print \"m = %d and n = %d\" %(m,n)\n", + "print \"m+n = %d\" % (m+n) # 54+20 = 74\n", + "print \"m-n = %d\" % (m-n) # 54-20 = 34\n", + "print \"m*n = %d\" % (m*n)# 54*20 = 1080\n", + "print \"m/n = %d\" % (m/n) # 54/20 = 2\n", + "print \"m modulo by n = %d\" % (m%n) # 54%20 = 14" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "m = 54 and n = 20\n", + "m+n = 74\n", + "m-n = 34\n", + "m*n = 1080\n", + "m/n = 2\n", + "m modulo by n = 14\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.5, page no. 21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "m = 44\n", + "m += 1\n", + "n = m\n", + "print \"m = %d , n = %d\" %(m,n)\n", + "m = 44\n", + "n = m # the post-increment operator is applied to m\n", + "m += 1\n", + "print \"m = %d , n = %d\" %(m,n)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "m = 45 , n = 45\n", + "m = 45 , n = 44\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.6, page no. 22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n=22\n", + "print \"n = %d\" % n\n", + "n += 9 # adds 9 to n\n", + "print \"After n += 9, n = %d\" % n\n", + "n -= 5 # subtracts 5 from n\n", + "print \"After n -= 5, n = %d\" % n\n", + "n *= 2 # multiplies n by 3\n", + "print \"After n *= 2, n = %d\" % n \n", + "n /= 3 # divides n by 9\n", + "print \"After n /= 3, n = %d\" % n \n", + "n %= 7 # reduces n to the remainder from dividing by 4\n", + "print 'After n modulo by 7 n = %d' %n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 22\n", + "After n += 9, n = 31\n", + "After n -= 5, n = 26\n", + "After n *= 2, n = 52\n", + "After n /= 3, n = 17\n", + "After n modulo by 7 n = 3\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.7, page no. 23" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "x=54.0\n", + "y=20.0\n", + "print \"x = %f and y = %f\" %(x,y)\n", + "print \"x+y = %f\" %(x+y) # 54.0+20.0 = 74.0\n", + "print \"x-y = %f\" % (x-y) # 54.0-20.0 = 34.0\n", + "print \"x*y = %f\" %( x*y) # 54.0*20.0 = 1080.0\n", + "print \"x/y = %f\" % (x/y) # 54.0/20.0 = 2.7\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 54.000000 and y = 20.000000\n", + "x+y = 74.000000\n", + "x-y = 34.000000\n", + "x*y = 1080.000000\n", + "x/y = 2.700000\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.8, page no. 23s" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "print \"Number of bytes used:\\n\"\n", + "\n", + "print \" char: %d \" % sys.getsizeof('a')\n", + "print \" int : %d \" % sys.getsizeof(int(1))\n", + "print \" string : %d \" % sys.getsizeof(str('hellololdei'))\n", + "print \"float : %d\" % sys.getsizeof(float(1.1))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number of bytes used:\n", + "\n", + " char: 22 \n", + " int : 12 \n", + " string : 32 \n", + "float : 16\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.9, page no. 24" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "\n", + "fbits = 8*sys.getsizeof(float(123))\n", + "\n", + "# each byte contains 8 bits\n", + "print \"float uses : %d bits:\\n\\t\" % fbits " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "float uses : 128 bits:\n", + "\t\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.10, page no. 25" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "v = 1234.56789\n", + "n = int(v);\n", + "print \"v = %f, n = %d\" %(v,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "v = 1234.567890, n = 1234\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.11, page no. 26" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "c='A'\n", + "print \"char c = \" + c\n", + "k=c;\n", + "print \"k = \" + k \n", + "m=k;\n", + "print \"m = \" + m \n", + "n=m\n", + "print \"n = \" + n\n", + "x=m\n", + "print \"x = \" + x \n", + "y=x\n", + "print \"y = \" + y" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "char c = A\n", + "k = A\n", + "m = A\n", + "n = A\n", + "x = A\n", + "y = A\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.12, page no. 27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n=1000\n", + "print \"n = %d\" % n\n", + "n *= 1000 # multiplies n by 1000\n", + "print \"n = %d\" % n\n", + "n *= 1000 # multiplies n by 1000\n", + "print \"n = %d\" % n\n", + "n *= 1000 # multiplies n by 1000\n", + "print \"n = %d\" % n\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 1000\n", + "n = 1000000\n", + "n = 1000000000\n", + "n = 1000000000000\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.13, page no. 27" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "x=1000.0\n", + "print \"x = %f\" % x\n", + "x *= x # multiplies n by itself; i.e., it squares x\n", + "print \"x = %f\" % x\n", + "x *= x # multiplies n by itself; i.e., it squares x\n", + "print \"x = %f\" % x\n", + "x *= x # multiplies n by itself; i.e., it squares x\n", + "print \"x = %f\" % x\n", + "x *= x # multiplies n by itself; i.e., it squares x\n", + "print \"x = %f\" % x\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 1000.000000\n", + "x = 1000000.000000\n", + "x = 1000000000000.000000\n", + "x = 999999999999999983222784.000000\n", + "x = 1000000000000000043845843045076197354634047651840.000000\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.14, page no. 28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "x = 1000/3.0\n", + "print \"x = %f\" %x # x = 1000/3\n", + "y = x - 333.0\n", + "print \"y = %f\" % y # y = 1/3\n", + "z = 3*y - 1.0\n", + "print \"z = %f\" %z # z = 3(1/3) - 1\n", + "if (z == 0):\n", + " print \"z == 0.\\n\"\n", + "else:\n", + " print \"z does not equal 0.\\n\" # z != 0\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 333.333333\n", + "y = 0.333333\n", + "z = -0.000000\n", + "z does not equal 0.\n", + "\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.15, page no. 28" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "\n", + "a = float(raw_input(\"Enter the coefficients of a quadratic equation:\\n a : \"))\n", + "b = float(raw_input('b : '))\n", + "c = float(raw_input('c : '))\n", + "\n", + "print \"The equation is: \",\n", + "print a,\n", + "print \"*x*x + \",\n", + "print b,\n", + "print \"*x + \" ,\n", + "print c,\n", + "print \" = 0\" \n", + "\n", + "d = b*b - 4*a*c # discriminant\n", + "sqrtd = math.sqrt(d)\n", + "x1 = (-b + sqrtd)/(2*a)\n", + "x2 = (-b - sqrtd)/(2*a)\n", + "print \"The solutions are:\"\n", + "print \"\\tx1 = %f\" % x1\n", + "print \"\\tx2 = %f\" % x2\n", + "print \"Check:\" \n", + "print \"\\ta*x1*x1 + b*x1 + c = %f\" %( a*x1*x1 + b*x1 + c)\n", + "print \"\\ta*x2*x2 + b*x2 + c = %f\" %( a*x2*x2 + b*x2 + c)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the coefficients of a quadratic equation:\n", + " a : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "b : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "c : -3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The equation is: 2.0 *x*x + 1.0 *x + -3.0 = 0\n", + "The solutions are:\n", + "\tx1 = 1.000000\n", + "\tx2 = -1.500000\n", + "Check:\n", + "\ta*x1*x1 + b*x1 + c = 0.000000\n", + "\ta*x2*x2 + b*x2 + c = 0.000000\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.17, page no. 31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "x = float(raw_input(\"Enter float: \"))\n", + "print \"Its reciprocal is: \",\n", + "print 1/x " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter float: 234.567e89\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Its reciprocal is: 4.2631742743e-92\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.18, page no. 31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "x = 11\n", + "# ERROR: this is not in the scope of x\n", + "if True:\n", + " x = 22 # OK: this is in the scope of x\n", + " y = 33 # ERROR: this is not in the scope of y\n", + " x = 44 # OK: this is in the scope of x\n", + " y = 55 # OK: this is in the scope of y\n", + "x = 66 # OK: this is in the scope of x\n", + "y = 77 # ERROR: this is not in the scope of y\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.19, page no. 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# this x is global\n", + "x = 11\n", + "\n", + "if True:\n", + " # illustrates the nested and parallel scopes:\n", + " x = 22\n", + " # begin scope of internal block\n", + " if True:\n", + " x = 33\n", + " print \"In block inside main(): x = %d \" % x\n", + " # end scope of internal block\n", + "print \"In main(): x = %d\" %x \n", + "print \"In main(): x = %d \"% x" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In block inside main(): x = 33 \n", + "In main(): x = 33\n", + "In main(): x = 33 \n" + ] + } + ], + "prompt_number": 18 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch3.ipynb b/Schaum's_Outline/ch3.ipynb new file mode 100755 index 00000000..d023e19b --- /dev/null +++ b/Schaum's_Outline/ch3.ipynb @@ -0,0 +1,1153 @@ +{ + "metadata": { + "name": "ch3" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3: Selection" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.1, page no. 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two positive integers: \";\n", + "n = int(raw_input())\n", + "d = int(raw_input())\n", + "if (n%d):\n", + " print \"%d is not divisible by %d\" %(n,d)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two positive integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "66\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "66 is not divisible by 7\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.2, page no. 37" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two positive integers: \";\n", + "n = int(raw_input())\n", + "d = int(raw_input())\n", + "if (n%d):\n", + " print \"%d is not divisible by %d\" %(n,d)\n", + "else:\n", + " print \"%d is divisible by %d\" %(n,d)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two positive integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "56\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "56 is divisible by 7\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.3, page no. 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two integers: \"\n", + "m = int(raw_input())\n", + "n = int(raw_input())\n", + "\n", + "if (m < n):\n", + " print \"%d is the minimum.\" %m\n", + "else:\n", + " print \"%d is the minimum.\" %n\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "55 is the minimum.\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.4, page no. 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter an integer: \"\n", + "n = int(raw_input())\n", + "if (n = 22):\n", + " print \"%d = 22\" %n\n", + "else: \n", + " print \"%d != 22\" %n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 3)", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m if (n = 22):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.5, page no. 39" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter three integers: \"\n", + "n1 = int(raw_input())\n", + "n2 = int(raw_input())\n", + "n3 = int(raw_input())\n", + "\n", + "m=n1\n", + "# now min <= n1\n", + "if (n2 < m):\n", + " m = n2 # now min <= n1 and min <= n2\n", + "if (n3 < m):\n", + " m = n3 # now min <= n1, min <= n2, and min <= n3\n", + "print \"Their minimum is %d\" % m" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Their minimum is 33\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.6, page no. 39" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two integers: \"\n", + "x = int(raw_input())\n", + "y = int(raw_input())\n", + "\n", + "if (x > y):\n", + " temp=x\n", + " x = y\n", + " y = temp\n", + " \n", + "\n", + "print \"%d <= %d\" %(x,y)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "66\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "44 <= 66\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.7, page no. 40" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n=44\n", + "print \"n = %d\" % n \n", + "if True:\n", + " # scope extends over 4 lines\n", + " print \"Enter an integer: \"\n", + " n = int(raw_input())\n", + " print \"n = %d\" % n \n", + "\n", + "if True:\n", + " print \"n = %d\" % n \n", + " # the n that was declared first\n", + "if True:\n", + " print \"n = %d\" % n \n", + "\n", + "print \"n = %d\" % n " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 44\n", + "Enter an integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 77\n", + "n = 77\n", + "n = 77\n", + "n = 77\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.8, page no. 41" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter three integers: \"\n", + "n1 = int(raw_input())\n", + "n2 = int(raw_input())\n", + "n3 = int(raw_input())\n", + "if (n1 <= n2 and n1 <= n3):\n", + " print \"Their minimum is %d\" % n1\n", + " \n", + "if (n2 <= n1 and n2 <= n3):\n", + " print \"Their minimum is %d \" % n2 \n", + "if (n3 <= n1 and n3 <= n2):\n", + " print \"Their minimum is %d\" % n3 \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Their minimum is 33 \n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.9, page no. 41" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Are you enrolled (y/n): \"\n", + "ans = raw_input()\n", + "if (ans == 'Y' or ans == 'y'):\n", + " print \"You are enrolled.\\n\"\n", + "else: \n", + " print \"You are not enrolled.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Are you enrolled (y/n): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You are enrolled.\n", + "\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.10, page no. 42" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "print \"Enter two positive integers: \";\n", + "n = int(raw_input())\n", + "d = int(raw_input())\n", + "\n", + "if (d != 0 and n%d == 0): \n", + " print \"%d divides %d\" %(d,n)\n", + "else:\n", + " print \"%d does not divide %d\"% (d,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two positive integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "6 does not divide 33\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.11, page no. 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter three integers: \"\n", + "n1 = int(raw_input())\n", + "n2 = int(raw_input())\n", + "n3 = int(raw_input())\n", + "\n", + "if (n1 >= n2 >= n3):\n", + " print \"max = x\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.12, page no. 43" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two positive integers: \"\n", + "n = int(raw_input())\n", + "d = int(raw_input())\n", + "\n", + "if (d != 0):\n", + " if (n%d == 0):\n", + " print d,\n", + " print \" divides %d\" % n \n", + " else:\n", + " print \"%d does not divide %d\" %(d,n)\n", + "else:\n", + " print '%d does not divide %d '%(d,n)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two positive integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "44 does not divide 55\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.13, page no. 44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter three integers: \"\n", + "n1 = int(raw_input())\n", + "n2 = int(raw_input())\n", + "n3 = int(raw_input())\n", + "if (n1 < n2):\n", + " if (n1 < n3):\n", + " print \"Their minimum is : %d\" % n1\n", + " else:\n", + " print \"Their minimum is : %d\" % n3\n", + "else: # n1 >= n2\n", + " if (n2 < n3):\n", + " print \"Their minimum is : %d\" % n2\n", + " else:\n", + " print \"Their minimum is %d\" % n3" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Their minimum is : 33\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.14, page no. 44" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Pick a number from 1 to 8.\" \n", + "answer = int(raw_input())\n", + "print \"Is it less than 5? (y|n): \"\n", + "answer = raw_input()\n", + "if (answer == 'y'): # 1 <= n <= 4\n", + " print \"Is it less than 3? (y|n): \"\n", + " answer = raw_input() \n", + " if (answer == 'y'): # 1 <= n <= 2\n", + " print \"Is it less than 2? (y|n): \"\n", + " answer = raw_input()\n", + " if (answer == 'y'):\n", + " print \"Your number is 1.\"\n", + " else:\n", + " print \"Your number is 2.\"\n", + " else: # 3 <= n <= 4\n", + " print \"Is it less than 4? (y|n): \"\n", + " answer = raw_input()\n", + " if (answer == 'y'):\n", + " print \"Your number is 3.\"\n", + " else:\n", + " print \"Your number is 4.\"\n", + "else: # 5 <= n <= 8\n", + " print \"Is it less than 7? (y|n): \"\n", + " answer = raw_input()\n", + " if (answer == 'y'): # 5 <= n <= 6\n", + " print \"Is it less than 6? (y|n): \"\n", + " answer = raw_input()\n", + " if (answer == 'y'):\n", + " print \"Your number is 5.\"\n", + " else:\n", + " print \"Your number is 6.\" \n", + " else: # 7 <= n <= 8\n", + " print \"Is it less than 8? (y|n): \"\n", + " answer = raw_input()\n", + " if (answer == 'y'):\n", + " print \"Your number is 7.\" \n", + " else:\n", + " print \"Your number is 8.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Pick a number from 1 to 8.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Is it less than 5? (y|n): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "n\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Is it less than 7? (y|n): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "y\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Is it less than 6? (y|n): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "n\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your number is 6.\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.15, page no. 46" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "language = raw_input(\"Engl., Fren., Ger., Ital., or Rus.? (e|f|g|i|r): \")\n", + "\n", + "if (language == 'e'): \n", + " print \"Welcome to ProjectEuclid.\"\n", + "elif (language == 'f'):\n", + " print \"Bon jour, ProjectEuclid.\"\n", + "elif (language == 'g'):\n", + " print \"Guten tag, ProjectEuclid.\"\n", + "elif (language == 'i'):\n", + " print \"Bon giorno, ProjectEuclid.\"\n", + "elif (language == 'r'):\n", + " print \"Dobre utre, ProjectEuclid.\"\n", + "else:\n", + " print \"Sorry; we don't speak your language.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Engl., Fren., Ger., Ital., or Rus.? (e|f|g|i|r): i\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Bon giorno, ProjectEuclid.\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.16, page no. 47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "score = int(raw_input(\"Enter your test score: \"))\n", + "a = int(score/10)\n", + "if a == 10 or a == 9:\n", + " print \"Your grade is an A.\"\n", + "elif a == 8:\n", + " print \"Your grade is a B.\" \n", + "elif a == 7:\n", + " print \"Your grade is a C.\" \n", + "elif a == 6:\n", + " print \"Your grade is a D.\"\n", + "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", + " print \"Your grade is an F.\" \n", + "else:\n", + " print \"Error: score is out of range.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your test score: 83\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your grade is a B.\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.17, page no. 47" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "score = int(raw_input(\"Enter your test score: \"))\n", + "a = int(score/10)\n", + "if a == 10 or a == 9:\n", + " print \"Your grade is an A.\"\n", + "elif a == 8:\n", + " print \"Your grade is a B.\" \n", + "elif a == 7:\n", + " print \"Your grade is a C.\" \n", + "elif a == 6:\n", + " print \"Your grade is a D.\"\n", + "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", + " print \"Your grade is an F.\" \n", + "else:\n", + " print \"Error: score is out of range.\\n\"\n", + "\n", + "print \"Goodbye.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your test score: 83\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your grade is a B.\n", + "Goodbye.\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.18, page no. 48" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "score = int(raw_input(\"Enter your test score: \"))\n", + "a = int(score/10)\n", + "if a == 10 or a == 9:\n", + " print \"Your grade is an A.\"\n", + "elif a == 8:\n", + " print \"Your grade is a B.\" \n", + "elif a == 7:\n", + " print \"Your grade is a C.\" \n", + "elif a == 6:\n", + " print \"Your grade is a D.\"\n", + "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", + " print \"Your grade is an F.\" \n", + "else:\n", + " print \"Error: score is out of range.\\n\"\n", + "\n", + "print \"Goodbye.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your test score: 83\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your grade is a B.\n", + "Goodbye.\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.19, page no. 49" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter two integers: \"\n", + "m = int(raw_input())\n", + "n = int(raw_input())\n", + "print min(m,n),\n", + "print 'is the minimum'" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "33 is the minimum\n" + ] + } + ], + "prompt_number": 19 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch4.ipynb b/Schaum's_Outline/ch4.ipynb new file mode 100755 index 00000000..557d2d6a --- /dev/null +++ b/Schaum's_Outline/ch4.ipynb @@ -0,0 +1,1633 @@ +{ + "metadata": { + "name": "ch4" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 4: Iteration" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.1, page no. 60" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "i=1\n", + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "s=0\n", + "while (i <= n):\n", + " s += i\n", + " i += 1\n", + "print \"The sum of the first %d integers is %d\" %(i,s)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 6 integers is 15\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.2, page no. 61" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "s=0.0\n", + "i=0\n", + "while (s < bound):\n", + " i += 1\n", + " s += 1.0/i\n", + "\n", + "print \"The sum of the first %d reciprocals is %f\" %(i,s)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 83 reciprocals is 5.002068\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.3, page no. 61" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "print \"Enter a positive number: \"\n", + "x = float(raw_input())\n", + "while (x > 0):\n", + " print \"sqrt(%d) = %f \"%(x,math.sqrt(x))\n", + " print \"Enter another positive number (or 0 to quit): \"\n", + " x = float(raw_input())\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive number: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "sqrt(5) = 2.236068 \n", + "Enter another positive number (or 0 to quit): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "sqrt(3) = 1.732051 \n", + "Enter another positive number (or 0 to quit): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.4, page no. 62" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "i=1\n", + "print \"Enter a positive integer: \";\n", + "n = int(raw_input())\n", + "s=0\n", + "while(True):\n", + " if (i > n):\n", + " break # terminates the loop immediately\n", + " s += i\n", + " i += 1\n", + "print \"The sum of the first %d integers is %d\" %(n,s)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 5 integers is 15\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.5, page no. 62\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", + "f0=0\n", + "f1=1\n", + "while (True):\n", + " f2 = f0 + f1\n", + " if (f2 > bound):\n", + " break\n", + " print \", %d\" % f2,\n", + " f0 = f1\n", + " f1 = f2\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Fibonacci numbers < 10:\n", + "0, 1 , 1 , 2 , 3 , 5 , 8\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.6, page no. 63" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", + "f0=0\n", + "f1=1\n", + "while (True):\n", + " f2 = f0 + f1\n", + " if (f2 > bound):\n", + " sys.exit(0)\n", + " print \", %d\" % f2,\n", + " f0 = f1\n", + " f1 = f2\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "ename": "SystemExit", + "evalue": "0", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Fibonacci numbers < 10:\n", + "0, 1 , 1 , 2 , 3 , 5 , 8" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.7, page no. 63" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", + "f0=0\n", + "f1=1\n", + "# Error : infinite loop !\n", + "while (True):\n", + " f2 = f0 + f1\n", + " # By commenting the below if statement, it goes to infinite.\n", + " if (f2 > bound):\n", + " break\n", + " print \", %d\" % f2,\n", + " f0 = f1\n", + " f1 = f2" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n", + "Fibonacci numbers < 10:\n", + "0, 1 , 1 , 2 , 3 , 5 , 8\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.8, page no. 64" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "i=0\n", + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "s=0\n", + "while i<=n:\n", + " s += i\n", + " i += 1\n", + "print \"The sum of the first %d integers is %d\" %(n,s)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 10 integers is 55\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.9, page no. 65" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "print \"Factorial numbers < %d:\\n1, 1\" %bound,\n", + "f=1\n", + "i=1\n", + "while f < bound:\n", + " i += 1\n", + " f *= i\n", + " print \", %d\" %f,\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Factorial numbers < 10:\n", + "1, 1 , 2 , 6 , 24\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.10, page no. 66" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "s=0;\n", + "for i in range(0,n+1):\n", + " s += i\n", + "print \"The sum of the first %d integers is %d\" %(n,s)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 10 integers is 55\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.11, page no. 66" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "s=0\n", + "for i in range(1,n/2): # the scope of this i is this loop\n", + " s += i\n", + "\n", + "for i in range(n/2,n+1): # the scope of this i is this loop\n", + " s += i\n", + "print \"The sum of the first %d integers is %d\" % (n,s)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 10 integers is 55\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.12, page no. 66" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter a positive integer: \"\n", + "bound = int(raw_input())\n", + "\n", + "print \"Factorial numbers that are <= %d:\\n1, 1\" %bound,\n", + "f=1\n", + "for i in range(2,bound+1):\n", + " f *= i\n", + " print \", %d\" % f,\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Factorial numbers that are <= 10:\n", + "1, 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 , 3628800\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.13, page no. 67" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "for i in range(10,0,-1):\n", + " print i,\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "10 9 8 7 6 5 4 3 2 1\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.14, page no. 67" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "prime = True\n", + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "if (n < 2):\n", + " print \"%d is not prime.\" %n\n", + " prime = False\n", + "elif (n < 4):\n", + " print \"%d is prime.\" %n\n", + " prime = False\n", + "elif (n%2 == 0):\n", + " print \"%d = 2* %d\" %(n,n/2)\n", + " prime = False\n", + "else:\n", + " for d in range(3,n/2+1):\n", + " if (n%d == 0):\n", + " print \"%d = %d * %d\" %(n,d,n/d)\n", + " prime = False\n", + "if prime: \n", + " print \"%d is prime.\"%n\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "11 is prime.\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.15, page no. 68" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter positive integers (0 to quit): \";\n", + "n = int(raw_input())\n", + "m = n\n", + "while n > 0:\n", + " n = int(raw_input())\n", + " if n > m :\n", + " m = n\n", + "\n", + "print \"max = %d\" % m" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter positive integers (0 to quit): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "19\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "max = 42\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.16, page no. 68" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter positive integers (0 to quit): \";\n", + "n = int(raw_input())\n", + "m = n\n", + "while n > 0: \n", + " if n < m :\n", + " m = n\n", + " n = int(raw_input())\n", + "\n", + "print \"min = %d\" % m\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter positive integers (0 to quit): \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "19\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "min = 1\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.17, page no. 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "m = 95\n", + "n = 11\n", + "while m%n > 0:\n", + " print \"%d modulo %d = %d\" %(m,n,m%n)\n", + " m -= 3\n", + " n += 1\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "95 modulo 11 = 7\n", + "92 modulo 12 = 8\n", + "89 modulo 13 = 11\n", + "86 modulo 14 = 2\n", + "83 modulo 15 = 8\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.18, page no. 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "for x in range(1,13):\n", + " for y in range(1,13):\n", + " print \"%4d\" % (x*y),\n", + " print \"\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 1 2 3 4 5 6 7 8 9 10 11 12 \n", + " 2 4 6 8 10 12 14 16 18 20 22 24 \n", + " 3 6 9 12 15 18 21 24 27 30 33 36 \n", + " 4 8 12 16 20 24 28 32 36 40 44 48 \n", + " 5 10 15 20 25 30 35 40 45 50 55 60 \n", + " 6 12 18 24 30 36 42 48 54 60 66 72 \n", + " 7 14 21 28 35 42 49 56 63 70 77 84 \n", + " 8 16 24 32 40 48 56 64 72 80 88 96 \n", + " 9 18 27 36 45 54 63 72 81 90 99 108 \n", + " 10 20 30 40 50 60 70 80 90 100 110 120 \n", + " 11 22 33 44 55 66 77 88 99 110 121 132 \n", + " 12 24 36 48 60 72 84 96 108 120 132 144 \n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.19, page no. 70" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "# defines pow() and log()\n", + "\n", + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "d=0 # the discrete binary logarithm of n\n", + "p2d=1 # = 2^d\n", + "i = n\n", + "while i > 1:\n", + " # INVARIANT: 2^d <= n/i < 2*2^d\n", + " p2d=math.pow(2,d) # = 2^d\n", + " print \"%2d <= %2d\" %(p2d,2*p2d)\n", + " i /= 2\n", + " d += 1\n", + "\n", + "p2d=math.pow(2,d) # = 2^d\n", + "print \"%2d <= %2d < %2d\" %(p2d,n,2*p2d)\n", + "print \" The discrete binary logarithm of is %d\" % d \n", + "lgn = math.log(n)/math.log(2) # base 2 logarithm\n", + "print \"The continuous binary logarithm of is %f\" % lgn" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "17\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 1 <= 2\n", + " 2 <= 4\n", + " 4 <= 8\n", + " 8 <= 16\n", + "16 <= 17 < 32\n", + " The discrete binary logarithm of is 4\n", + "The continuous binary logarithm of is 4.087463\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.20, page no. 71" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "i=1\n", + "print \"Enter a positive integer: \"\n", + "n = int(raw_input())\n", + "s=0\n", + "while (True):\n", + " if (i > n):\n", + " break\n", + " s += i\n", + " i += 1\n", + "\n", + "print \"The sum of the first %d integers is %d\" %(i,s)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a positive integer: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The sum of the first 11 integers is 55\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.21, page no. 71" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "count=0\n", + "s=0\n", + "print \"Enter positive integers (0 to quit):\" \n", + "while True: # \"forever\"\n", + " print \"\\t %d :\" %(count + 1),\n", + " n = int(raw_input())\n", + " if (n <= 0):\n", + " break\n", + " count += 1\n", + " s += n\n", + "\n", + "print \"The average of those %d positive numbers is \" %count,\n", + "print float(s)/count\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter positive integers (0 to quit):\n", + "\t 1 :" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t 2 :" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "32\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t 3 :" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t 4 :" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The average of those 3 positive numbers is 18.3333333333\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.22, page no. 72" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "for x in range(1,13):\n", + " for y in range(1,13):\n", + " if y>x:\n", + " break\n", + " else:\n", + " print '%4d' %(x*y),\n", + " print ''\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 1 \n", + " 2 4 \n", + " 3 6 9 \n", + " 4 8 12 16 \n", + " 5 10 15 20 25 \n", + " 6 12 18 24 30 36 \n", + " 7 14 21 28 35 42 49 \n", + " 8 16 24 32 40 48 56 64 \n", + " 9 18 27 36 45 54 63 72 81 \n", + " 10 20 30 40 50 60 70 80 90 100 \n", + " 11 22 33 44 55 66 77 88 99 110 121 \n", + " 12 24 36 48 60 72 84 96 108 120 132 144 \n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.23, page no. 73" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "while True:\n", + " n = int(raw_input('Enter int : '))\n", + " if (n%2 == 0):\n", + " continue\n", + " if (n%3 == 0):\n", + " break\n", + " print \"\\tBottom of loop.\\n\"\n", + "print \"\\tOutside of loop.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter int : 5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tBottom of loop.\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter int : 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter int : 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter int : 9\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tOutside of loop.\n", + "\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.24, page no. 74" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "N=5\n", + "done=False\n", + "for i in range(N):\n", + " for j in range(N):\n", + " if done:\n", + " break\n", + " for k in range(N):\n", + " if done:\n", + " break\n", + " if (i+j+k>N):\n", + " done = True\n", + " else:\n", + " print i+j+k,\n", + " print \" \",\n", + " print \"* \"\n", + " print \".\" \n", + " done = False\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 1 2 3 4 * \n", + "1 2 3 4 5 * \n", + "2 3 4 5 * \n", + ".\n", + "1 2 3 4 5 * \n", + "2 3 4 5 * \n", + ".\n", + "2 3 4 5 * \n", + ".\n", + "3 4 5 * \n", + ".\n", + "4 5 * \n", + ".\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.25, page no. 75" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "N=5\n", + "done=False\n", + "for i in range(N):\n", + " for j in range(N):\n", + " if done:\n", + " break\n", + " for k in range(N):\n", + " if done:\n", + " break\n", + " if (i+j+k>N):\n", + " done = True\n", + " else:\n", + " print i+j+k,\n", + " print \" \",\n", + " print \"* \"\n", + " print \".\" \n", + " done = False\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 1 2 3 4 * \n", + "1 2 3 4 5 * \n", + "2 3 4 5 * \n", + ".\n", + "1 2 3 4 5 * \n", + "2 3 4 5 * \n", + ".\n", + "2 3 4 5 * \n", + ".\n", + "3 4 5 * \n", + ".\n", + "4 5 * \n", + ".\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.26, page no. 76" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "\n", + "# prints pseudo-random numbers:\n", + "\n", + "for i in range(0,8):\n", + " print random.random()\n", + "\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.702115758628\n", + "0.969460447904\n", + "0.409934401112\n", + "0.700339443791\n", + "0.093528851602\n", + "0.132172955687\n", + "0.0162887279366\n", + "0.943010713478\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.27, page no. 77" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "# prints pseudo-random numbers:\n", + "print \"Enter seed: \"\n", + "seed = int(raw_input())\n", + "random.seed(seed);\n", + "for i in range(0,8):\n", + " print random.random()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter seed: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.62290169489\n", + "0.741786989261\n", + "0.795193565566\n", + "0.942450283777\n", + "0.73989857474\n", + "0.922324996665\n", + "0.0290052282836\n", + "0.465622654378\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.28, page no. 78" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "for i in range(0,8):\n", + " print random.random()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.943356716998\n", + "0.648974553137\n", + "0.900900491751\n", + "0.113205964653\n", + "0.469069047782\n", + "0.24657283262\n", + "0.543760859236\n", + "0.573941187928\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.29, page no. 79" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "print \"Enter minimum and maximum: \"\n", + "m = int(raw_input())\n", + "n = int(raw_input())\n", + "# lowest and highest numbers\n", + "r = n - m + 1\n", + "# number of numbers in range\n", + "for i in range(0,20):\n", + " j = int(random.random()*100 % r + m)\n", + " print j,\n", + " print \" \",\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter minimum and maximum: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "6 15 10 8 15 9 7 7 11 6 5 15 14 15 15 15 11 13 14 6 \n" + ] + } + ], + "prompt_number": 24 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch5.ipynb b/Schaum's_Outline/ch5.ipynb new file mode 100755 index 00000000..1fddf23f --- /dev/null +++ b/Schaum's_Outline/ch5.ipynb @@ -0,0 +1,1746 @@ +{ + "metadata": { + "name": "" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5: Functions\n" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.1, Page no:87" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "\n", + "# tests the sqrt() function:\n", + "for i in range(0,6):\n", + " print \"\\t %d \\t %f\" %(i,math.sqrt(i))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t 0 \t 0.000000\n", + "\t 1 \t 1.000000\n", + "\t 2 \t 1.414214\n", + "\t 3 \t 1.732051\n", + "\t 4 \t 2.000000\n", + "\t 5 \t 2.236068\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.2, Page no:88" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "# tests the identity sin 2x = 2 sin x cos x:\n", + "x = 0\n", + "while x < 2:\n", + " print \"%f \\t\\t %f \\t %f\" %(x,math.sin(2*x),2*math.sin(x)*math.cos(x))\n", + " x += 0.2\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.000000 \t\t 0.000000 \t 0.000000\n", + "0.200000 \t\t 0.389418 \t 0.389418\n", + "0.400000 \t\t 0.717356 \t 0.717356\n", + "0.600000 \t\t 0.932039 \t 0.932039\n", + "0.800000 \t\t 0.999574 \t 0.999574\n", + "1.000000 \t\t 0.909297 \t 0.909297\n", + "1.200000 \t\t 0.675463 \t 0.675463\n", + "1.400000 \t\t 0.334988 \t 0.334988\n", + "1.600000 \t\t -0.058374 \t -0.058374\n", + "1.800000 \t\t -0.442520 \t -0.442520\n", + "2.000000 \t\t -0.756802 \t -0.756802\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.3, Page no:90" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def cube(x):\n", + " # returns cube of x:\n", + " return x*x*x\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.4, Page no:91" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def cube(x):\n", + " # returns cube of x:\n", + " return x*x*x\n", + "\n", + "# tests the cube() function:\n", + "n=1\n", + "while (n != 0):\n", + " n = int(raw_input())\n", + " print \"\\tcube( %d ) = %d\" %(n,cube(n))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tcube( 4 ) = 64\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tcube( 2 ) = 8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tcube( 9 ) = 729\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tcube( 0 ) = 0\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.5, Page no:90" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def maximum(x,y):\n", + " # returns larger of the two given integers:\n", + " if (x < y):\n", + " return y\n", + " else:\n", + " return x\n", + "\n", + "# tests the max() function:\n", + "m = 1\n", + "n = 1\n", + "while m != 0: \n", + " m = int(raw_input())\n", + " n = int(raw_input())\n", + " print \"\\tmax( %d , %d ) = %d\" %(m,n,maximum(m,n))\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax( 5 , 2 ) = 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax( 0 , 3 ) = 3\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.6, Page no:93" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def maximum(x,y):\n", + " # returns larger of the two given integers:\n", + " if (x < y):\n", + " return y\n", + " else:\n", + " return x\n", + "\n", + "# tests the max() function:\n", + "m = 1\n", + "n = 1\n", + "while m != 0: \n", + " m = int(raw_input())\n", + " n = int(raw_input())\n", + " print \"\\tmax( %d , %d ) = %d\" %(m,n,maximum(m,n))\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax( 5 , 2 ) = 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax( 0 , 3 ) = 3\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.8, Page no:94" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "# returns larger of the two given integers:\n", + "\n", + "m = 1\n", + "n = 1\n", + "while m!=0:\n", + " m = int(raw_input())\n", + " n = int(raw_input())\n", + " print \"\\tmax(%d,%d) = %d\" %(m,n, max(m,n))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax(5,4) = 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax(4,3) = 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax(8,0) = 8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\tmax(0,5) = 5\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.9, Page no:95" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def fact(n):\n", + " if (n < 0):\n", + " return 0\n", + " f = 1\n", + " while (n > 1):\n", + " f *= n\n", + " n -= 1\n", + " return f\n", + "\n", + "for i in range(-1,6):\n", + " print fact(i),\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 1 1 2 6 24 120\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.10, Page no:95" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def fact(n):\n", + " if (n < 0):\n", + " return 0\n", + " f = 1\n", + " while (n > 1):\n", + " f *= n\n", + " n -= 1\n", + " return f\n", + "\n", + "\n", + "def perm(n,k):\n", + " # returns P(n,k), the number of permutations of k from n:\n", + " if (n < 0 or k < 0 or k > n):\n", + " return 0\n", + " return fact(n)/fact(n-k)\n", + "\n", + "for i in range(-1,8):\n", + " for j in range(-1,i+2):\n", + " print perm(i,j),\n", + " print ''\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 0 \n", + "0 1 0 \n", + "0 1 1 0 \n", + "0 1 2 2 0 \n", + "0 1 3 6 6 0 \n", + "0 1 4 12 24 24 0 \n", + "0 1 5 20 60 120 120 0 \n", + "0 1 6 30 120 360 720 720 0 \n", + "0 1 7 42 210 840 2520 5040 5040 0 \n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.11, Page no:96" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def printDate(m,d,y):\n", + " # prints the given date in literal form:\n", + " if (m < 1 or m > 12 or d < 1 or d > 31 or y < 0):\n", + " print \"Error: parameter out of range.\\n\"\n", + " return\n", + " if m == 1:\n", + " print \"January \",\n", + " elif m ==2:\n", + " print \"February \",\n", + " elif m==3 :\n", + " print \"March \",\n", + " elif m==4:\n", + " print \"April \",\n", + " elif m==5:\n", + " print \"May \",\n", + " elif m==6:\n", + " print \"June \",\n", + " elif m==7:\n", + " print \"July \",\n", + " elif m==8:\n", + " print \"August \",\n", + " elif m==9:\n", + " print \"September \",\n", + " elif m==10:\n", + " print \"October \",\n", + " elif m==1:\n", + " print \"November \",\n", + " else:\n", + " print \"December \",\n", + " print d , \", \", y \n", + "\n", + "# tests the printDate() function:\n", + "month = 1\n", + "while month > 0:\n", + " month = int(raw_input())\n", + " day = int(raw_input())\n", + " year = int(raw_input())\n", + " printDate(month,day,year)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "1989\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "September 12 , 1989\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2001\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Error: parameter out of range.\n", + "\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.12, Page no:98" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import string\n", + "def ispunct(s):\n", + " return all(c in string.punctuation for c in s)\n", + "def printCharCategory(c):\n", + " # prints the category to which the given character belongs:\n", + " print \"The character [\" + c + \"] is a \",\n", + " if(c.isdigit()):\n", + " print \"digit.\\n\"\n", + " elif (c.islower()):\n", + " print \"lower-case letter.\\n\"\n", + " elif (c.isupper()): \n", + " print \"capital letter.\\n\"\n", + " elif (c.isspace()):\n", + " print \"white space character.\\n\"\n", + " elif (ord(c) >= 10 and ord(c) <= 15 or ord(c) == 0):\n", + " print \"control character.\\n\"\n", + " elif (ispunct(c)):\n", + " print \"punctuation mark.\\n\"\n", + " else:\n", + " print \"Error.\\n\"\n", + "\n", + "# prints the category to which the given character belongs;\n", + "# tests the printCharCategory() function:\n", + "for c in range(128):\n", + " printCharCategory(chr(c))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The character [\u0000] is a control character.\n", + "\n", + "The character [\u0001] is a Error.\n", + "\n", + "The character [\u0002] is a Error.\n", + "\n", + "The character [\u0003] is a Error.\n", + "\n", + "The character [\u0004] is a Error.\n", + "\n", + "The character [\u0005] is a Error.\n", + "\n", + "The character [\u0006] is a Error.\n", + "\n", + "The character [\u0007] is a Error.\n", + "\n", + "The character [\b] is a Error.\n", + "\n", + "The character [\t] is a white space character.\n", + "\n", + "The character [\n", + "] is a white space character.\n", + "\n", + "The character [\u000b", + "] is a white space character.\n", + "\n", + "The character [\f", + "] is a white space character.\n", + "\n", + "The character [\r", + "] is a white space character.\n", + "\n", + "The character [\u000e] is a control character.\n", + "\n", + "The character [\u000f] is a control character.\n", + "\n", + "The character [\u0010] is a Error.\n", + "\n", + "The character [\u0011] is a Error.\n", + "\n", + "The character [\u0012] is a Error.\n", + "\n", + "The character [\u0013] is a Error.\n", + "\n", + "The character [\u0014] is a Error.\n", + "\n", + "The character [\u0015] is a Error.\n", + "\n", + "The character [\u0016] is a Error.\n", + "\n", + "The character [\u0017] is a Error.\n", + "\n", + "The character [\u0018] is a Error.\n", + "\n", + "The character [\u0019] is a Error.\n", + "\n", + "The character [\u001a] is a Error.\n", + "\n", + "The character [\u001b] is a Error.\n", + "\n", + "The character [\u001c", + "] is a Error.\n", + "\n", + "The character [\u001d", + "] is a Error.\n", + "\n", + "The character [\u001e", + "] is a Error.\n", + "\n", + "The character [\u001f] is a Error.\n", + "\n", + "The character [ ] is a white space character.\n", + "\n", + "The character [!] is a punctuation mark.\n", + "\n", + "The character [\"] is a punctuation mark.\n", + "\n", + "The character [#] is a punctuation mark.\n", + "\n", + "The character [$] is a punctuation mark.\n", + "\n", + "The character [%] is a punctuation mark.\n", + "\n", + "The character [&] is a punctuation mark.\n", + "\n", + "The character ['] is a punctuation mark.\n", + "\n", + "The character [(] is a punctuation mark.\n", + "\n", + "The character [)] is a punctuation mark.\n", + "\n", + "The character [*] is a punctuation mark.\n", + "\n", + "The character [+] is a punctuation mark.\n", + "\n", + "The character [,] is a punctuation mark.\n", + "\n", + "The character [-] is a punctuation mark.\n", + "\n", + "The character [.] is a punctuation mark.\n", + "\n", + "The character [/] is a punctuation mark.\n", + "\n", + "The character [0] is a digit.\n", + "\n", + "The character [1] is a digit.\n", + "\n", + "The character [2] is a digit.\n", + "\n", + "The character [3] is a digit.\n", + "\n", + "The character [4] is a digit.\n", + "\n", + "The character [5] is a digit.\n", + "\n", + "The character [6] is a digit.\n", + "\n", + "The character [7] is a digit.\n", + "\n", + "The character [8] is a digit.\n", + "\n", + "The character [9] is a digit.\n", + "\n", + "The character [:] is a punctuation mark.\n", + "\n", + "The character [;] is a punctuation mark.\n", + "\n", + "The character [<] is a punctuation mark.\n", + "\n", + "The character [=] is a punctuation mark.\n", + "\n", + "The character [>] is a punctuation mark.\n", + "\n", + "The character [?] is a punctuation mark.\n", + "\n", + "The character [@] is a punctuation mark.\n", + "\n", + "The character [A] is a capital letter.\n", + "\n", + "The character [B] is a capital letter.\n", + "\n", + "The character [C] is a capital letter.\n", + "\n", + "The character [D] is a capital letter.\n", + "\n", + "The character [E] is a capital letter.\n", + "\n", + "The character [F] is a capital letter.\n", + "\n", + "The character [G] is a capital letter.\n", + "\n", + "The character [H] is a capital letter.\n", + "\n", + "The character [I] is a capital letter.\n", + "\n", + "The character [J] is a capital letter.\n", + "\n", + "The character [K] is a capital letter.\n", + "\n", + "The character [L] is a capital letter.\n", + "\n", + "The character [M] is a capital letter.\n", + "\n", + "The character [N] is a capital letter.\n", + "\n", + "The character [O] is a capital letter.\n", + "\n", + "The character [P] is a capital letter.\n", + "\n", + "The character [Q] is a capital letter.\n", + "\n", + "The character [R] is a capital letter.\n", + "\n", + "The character [S] is a capital letter.\n", + "\n", + "The character [T] is a capital letter.\n", + "\n", + "The character [U] is a capital letter.\n", + "\n", + "The character [V] is a capital letter.\n", + "\n", + "The character [W] is a capital letter.\n", + "\n", + "The character [X] is a capital letter.\n", + "\n", + "The character [Y] is a capital letter.\n", + "\n", + "The character [Z] is a capital letter.\n", + "\n", + "The character [[] is a punctuation mark.\n", + "\n", + "The character [\\] is a punctuation mark.\n", + "\n", + "The character []] is a punctuation mark.\n", + "\n", + "The character [^] is a punctuation mark.\n", + "\n", + "The character [_] is a punctuation mark.\n", + "\n", + "The character [`] is a punctuation mark.\n", + "\n", + "The character [a] is a lower-case letter.\n", + "\n", + "The character [b] is a lower-case letter.\n", + "\n", + "The character [c] is a lower-case letter.\n", + "\n", + "The character [d] is a lower-case letter.\n", + "\n", + "The character [e] is a lower-case letter.\n", + "\n", + "The character [f] is a lower-case letter.\n", + "\n", + "The character [g] is a lower-case letter.\n", + "\n", + "The character [h] is a lower-case letter.\n", + "\n", + "The character [i] is a lower-case letter.\n", + "\n", + "The character [j] is a lower-case letter.\n", + "\n", + "The character [k] is a lower-case letter.\n", + "\n", + "The character [l] is a lower-case letter.\n", + "\n", + "The character [m] is a lower-case letter.\n", + "\n", + "The character [n] is a lower-case letter.\n", + "\n", + "The character [o] is a lower-case letter.\n", + "\n", + "The character [p] is a lower-case letter.\n", + "\n", + "The character [q] is a lower-case letter.\n", + "\n", + "The character [r] is a lower-case letter.\n", + "\n", + "The character [s] is a lower-case letter.\n", + "\n", + "The character [t] is a lower-case letter.\n", + "\n", + "The character [u] is a lower-case letter.\n", + "\n", + "The character [v] is a lower-case letter.\n", + "\n", + "The character [w] is a lower-case letter.\n", + "\n", + "The character [x] is a lower-case letter.\n", + "\n", + "The character [y] is a lower-case letter.\n", + "\n", + "The character [z] is a lower-case letter.\n", + "\n", + "The character [{] is a punctuation mark.\n", + "\n", + "The character [|] is a punctuation mark.\n", + "\n", + "The character [}] is a punctuation mark.\n", + "\n", + "The character [~] is a punctuation mark.\n", + "\n", + "The character [\u007f] is a Error.\n", + "\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.13, Page no:99" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import math\n", + "def isPrime(n):\n", + " # returns True if n is prime, False otherwise:\n", + " sqrtn = math.sqrt(n)\n", + " if (n < 2):\n", + " return False\n", + " # 0 and 1 are not primes\n", + " if (n < 4):\n", + " return True\n", + " # 2 and 3 are the first primes\n", + " if (n%2 == 0):\n", + " return False\n", + " # 2 is the only even prime\n", + " for d in range(3,int(sqrtn+1),2):\n", + " if (n%d == 0):\n", + " return False\n", + " # n has a nontrivial divisor\n", + " return True;\n", + "\n", + "for n in range(0,80):\n", + " if (isPrime(n)):\n", + " print n,\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.14, Page no:100" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def isLeapYear(y):\n", + " # returns true iff y is a leap year:\n", + " return (y % 4 == 0 and y % 100 != 0 or y % 400 == 0)\n", + "\n", + "# tests the isLeapYear() function:\n", + "n = 2\n", + "while n > 1:\n", + " n = int(raw_input())\n", + " if (isLeapYear(n)):\n", + " print \"%d is a leap year.\" % n\n", + " else:\n", + " print \"%d is not a leap year.\" %n\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2004\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "2004 is a leap year.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2006\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "2006 is not a leap year.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2013\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "2013 is not a leap year.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 is a leap year.\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.15, Page no: 101" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def age():\n", + " # prompts the user to input his/her age, and returns that value:\n", + " while (True):\n", + " print \"How old are you: \"\n", + " n = int(raw_input())\n", + " if (n < 0):\n", + " print \"\\a\\tYour age could not be negative.\"\n", + " elif (n > 120):\n", + " print \"\\a\\tYou could not be over 120.\"\n", + " else:\n", + " return n\n", + " print \"\\n\\tTry again.\\n\"\n", + "\n", + "a = age();\n", + "print \"\\nYou are %d years old.\" %a\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "How old are you: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "-12\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\u0007\tYour age could not be negative.\n", + "\n", + "\tTry again.\n", + "\n", + "How old are you: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "125\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\u0007\tYou could not be over 120.\n", + "\n", + "\tTry again.\n", + "\n", + "How old are you: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "24\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "You are 24 years old.\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.16, Page no: 102" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def swap(x,y):\n", + " # exchanges the values of x and y:\n", + " x[0],y[0] = y[0],x[0]\n", + "\n", + "a = [22.2]\n", + "b = [44.4]\n", + "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", + "swap(a,b)\n", + "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 22.20 , b = 44.40 \n", + "a = 44.40 , b = 22.20 \n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.17, Page no: 104" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python doesn't support pass value by reference. but can be done by passing list.\n", + "'''\n", + "\n", + "def f(x,y):\n", + " x[0]= 88\n", + " y[0] = 99\n", + "\n", + "# tests the f() function:\n", + "a = [22]\n", + "b = [44]\n", + "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", + "f(a,b)\n", + "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", + "f(2*a,b)\n", + "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 22.00 , b = 44.00 \n", + "a = 88.00 , b = 99.00 \n", + "a = 88.00 , b = 99.00 \n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.18, Page no: 105" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def computeCircle(r):\n", + " # returns the area and circumference of a circle with radius r:\n", + " PI = 3.141592653589793\n", + " area = PI*r*r\n", + " circumference = 2*PI*r\n", + " return area,circumference\n", + "\n", + "# tests the computeCircle() function:\n", + "print \"Enter radius: \"\n", + "r = int(raw_input())\n", + "a,c = computeCircle(r)\n", + "print \"area = %.2f , circumference = %.2f\" %(a,c)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter radius: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "area = 78.54 , circumference = 31.42\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.19, Page no: 106" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python passes variable by value and not by reference. So output would be differ.\n", + "'''\n", + "\n", + "\n", + "def f(x,y,z):\n", + " x[0] += z[0]\n", + " y[0] += z[0]\n", + " print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", + "\n", + "x = [22]\n", + "y = [33]\n", + "z = [44]\n", + "\n", + "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", + "f(x,y,z)\n", + "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", + "x[0] = 2*x[0] - 3\n", + "f(x,y,z)\n", + "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 22 , y = 33 , z = 44\n", + "x = 66 , y = 77 , z = 44\n", + "x = 66 , y = 77 , z = 44\n", + "x = 173 , y = 121 , z = 44\n", + "x = 173 , y = 121 , z = 44\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.20, Page no: 107" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def cube(x):\n", + " # returns cube of x:\n", + " return x*x*x\n", + "\n", + "# tests the cube() function:\n", + "print cube(4)\n", + "x = int(raw_input())\n", + "y = cube(2*x-3)\n", + "print y\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "64\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "343\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.21, Page no: 108" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Python has it's own scope so output would be differ.\n", + "'''\n", + "x = 11\n", + "\n", + "def f():\n", + " x = 44\n", + " print \"In f(): x = %d\" % x \n", + "\n", + "def g():\n", + " print \"In g(): x = %d\" % x \n", + "\n", + "x = 22\n", + "x = 33\n", + "print \"In block inside main(): x = %d\" % x\n", + "\n", + "\n", + "print \"In main(): x = %d\" % x \n", + "print \"In main(): ::x = %d\" % x \n", + "f()\n", + "g()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In block inside main(): x = 33\n", + "In main(): x = 33\n", + "In main(): ::x = 33\n", + "In f(): x = 44\n", + "In g(): x = 33\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.22, Page no: 109" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def max_(x, y,z=0):\n", + " if x > y and x > y:\n", + " return x\n", + " elif y > x and y > z:\n", + " return y\n", + " else:\n", + " return z\n", + " \n", + " \n", + "print max(99,77), \" \" , max(55,66,33)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "99 66\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.23, Page no: 110" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "# prints the quotient of two input integers:\n", + "print \"Enter two integers: \"\n", + "n = int(raw_input())\n", + "d = int(raw_input())\n", + "if (d == 0):\n", + " import sys\n", + " sys.exit(0)\n", + "print n , \"/\" , d , \" = \" , n/d \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two integers: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "8 / 2 = 4\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.24, Page no: 110" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def reciprocal(x):\n", + " #returns the reciprocal of x:\n", + " if (x == 0):\n", + " import sys\n", + " sys.exit(1); # terminate the program\n", + " return 1.0/x\n", + "\n", + "x = float(raw_input())\n", + "print reciprocal(x)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0.04\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.25, Page no: 111" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "This function evaluates the third degree polynomial a0 + a1x + a2x2 + a3x3. \n", + "'''\n", + "def p(x,a0,a1=0,a2=0,a3=0):\n", + " # returns a0 + a1*x + a2*x^2 + a3*x^3:\n", + " return (a0 + (a1 + (a2 + a3*x)*x)*x)\n", + "\n", + "\n", + "# tests the p() function:\n", + "x = 2.0003\n", + "print \"p(x,7) = %f\" % p(x,7)\n", + "print \"p(x,7,6) = %f\" % p(x,7,6)\n", + "print \"p(x,7,6,5) = %f\" % p(x,7,6,5)\n", + "print \"p(x,7,6,5,4) = %f\" % p(x,7,6,5,4)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "p(x,7) = 7.000000\n", + "p(x,7,6) = 19.001800\n", + "p(x,7,6,5) = 39.007800\n", + "p(x,7,6,5,4) = 71.022203\n" + ] + } + ], + "prompt_number": 24 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch6.ipynb b/Schaum's_Outline/ch6.ipynb new file mode 100755 index 00000000..2c52f179 --- /dev/null +++ b/Schaum's_Outline/ch6.ipynb @@ -0,0 +1,1276 @@ +{ + "metadata": { + "name": "ch6" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6: Arrays" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.1, page no. 126" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = [0, 0, 0]\n", + "a[2] = 55.55\n", + "a[0] = 11.11\n", + "a[1] = 33.33\n", + "print \"a[0] = \" , a[0] \n", + "print \"a[1] = \" , a[1] \n", + "print \"a[2] = \" , a[2] \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[0] = 11.11\n", + "a[1] = 33.33\n", + "a[2] = 55.55\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.2, page no. 127" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "SIZE=5 # defines the size N for 5 elements\n", + "a = []\n", + "# declares the array's elements as type double\n", + "print \"Enter \" , SIZE , \" numbers:\\t\"\n", + "for i in range(SIZE):\n", + " a.append(float(raw_input()))\n", + " \n", + "print \"In reverse order: \"\n", + "for i in range(SIZE-1,-1,-1):\n", + " print \"\\t\" , a[i]\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 5 numbers:\t\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11.11\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33.33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55.55\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77.77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "99.99\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "In reverse order: \n", + "\t99.99\n", + "\t77.77\n", + "\t55.55\n", + "\t33.33\n", + "\t11.11\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.3, page no. 128" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = [ 22.2, 44.4, 66.6 ]\n", + "\n", + "size = len(a)\n", + "for i in range(size):\n", + " print \"\\ta[\" , i , \"] = \" , a[i]\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\ta[ 0 ] = 22.2\n", + "\ta[ 1 ] = 44.4\n", + "\ta[ 2 ] = 66.6\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.4, page no. 128" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = [ 22.2, 44.4, 66.6 , 0 ,0,0,0]\n", + "size = len(a)\n", + "for i in range(size):\n", + " print \"\\ta[\" , i , \"] = \" , a[i] \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\ta[ 0 ] = 22.2\n", + "\ta[ 1 ] = 44.4\n", + "\ta[ 2 ] = 66.6\n", + "\ta[ 3 ] = 0\n", + "\ta[ 4 ] = 0\n", + "\ta[ 5 ] = 0\n", + "\ta[ 6 ] = 0\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.5, page no. 129" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import numpy\n", + "SIZE = 4\n", + "a = numpy.zeros(4)\n", + "# declares the array's elements as type float\n", + "for i in range(SIZE):\n", + " print \"\\ta[\" , i , \"] = \" , a[i]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\ta[ 0 ] = 0.0\n", + "\ta[ 1 ] = 0.0\n", + "\ta[ 2 ] = 0.0\n", + "\ta[ 3 ] = 0.0\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.6, page no. 129" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "SIZE=4\n", + "a = [ 33.3, 44.4, 55.5, 66.6 ]\n", + "for i in range(7): # ERROR: index is out of bounds!\n", + " print \"\\ta[\" , i , \"] = \" , a[i] \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m \u001b[1;36m33.3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m44.4\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m55.5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m66.6\u001b[0m \u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# ERROR: index is out of bounds!\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\ta[\"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m,\u001b[0m \u001b[1;34m\"] = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIndexError\u001b[0m: list index out of range" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\ta[ 0 ] = 33.3\n", + "\ta[ 1 ] = 44.4\n", + "\ta[ 2 ] = 55.5\n", + "\ta[ 3 ] = 66.6\n", + "\ta[ 4 ] = " + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.7, page no. 130" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = [ 22.2, 44.4, 66.6 ]\n", + "x=11.1\n", + "print \"x = \" , x \n", + "a.append(88.8) # ERROR: index is out of bounds!\n", + "print \"x = \" , x \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " x = 11.1\n", + "x = 11.1\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.8, page no. 130" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = [ 22.2, 44.4, 66.6 ]\n", + "x=11.1\n", + "print \"x = \" , x \n", + "a[3333] = 88.8 # ERROR: index is out of bounds!\n", + "print \"x = \" , x \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list assignment index out of range", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m11.1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3333\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m88.8\u001b[0m \u001b[1;31m# ERROR: index is out of bounds!\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "x = 11.1\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.9, page no. 131" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def sum_(a):\n", + " s = 0\n", + " for i in a:\n", + " s += i\n", + " return s\n", + " \n", + "a = [ 11, 33, 55, 77 ]\n", + "print \"sum(a) = \" , sum_(a) \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "sum(a) = 176\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.10, page no. 132" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def read(a):\n", + " print \"Enter integers. Terminate with 0:\\n\"\n", + " n = 1\n", + " while True:\n", + " n = int(raw_input(\"a[\" + str(len(a)) + \"]: \"))\n", + " if n == 0:\n", + " break\n", + " a.append(n)\n", + " \n", + "\n", + "def print_(a):\n", + " for i in a:\n", + " print i ,\n", + "\n", + "\n", + "a = []\n", + "read(a)\n", + "print \"The array has \" , len(a) , \" elements: \"\n", + "print_(a)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter integers. Terminate with 0:\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[0]: 11\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[1]: 22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[2]: 33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[3]: 44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "a[4]: 0\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The array has 4 elements: \n", + "11 22 33 44\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.11, page no. 133" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "a = [ 22, 44, 66, 88 ]\n", + "print \"a = \" , id(a) # the address of a[0]\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 169156908\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.12, page no. 133" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def index(x,a,n):\n", + " for i in range(len(a)):\n", + " if (a[i] == x):\n", + " return i\n", + " return n # x not found\n", + "\n", + "a = [ 22, 44, 66, 88, 44, 66, 55 ]\n", + "print \"index(44,a,7) = \" , index(44,a,7)\n", + "print \"index(50,a,7) = \" , index(50,a,7) \n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "index(44,a,7) = 1\n", + "index(50,a,7) = 7\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.13, page no. 134" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def sort(a,n):\n", + " # bubble sort:\n", + " n = len(a)\n", + " for i in range(n):\n", + " # bubble up max{a[0..n-i]}:\n", + " for j in range(n-i-1):\n", + " if (a[j] > a[j+1]):\n", + " a[j],a[j+1] = a[j+1],a[j]\n", + "\n", + "def print_(a):\n", + " for i in range(len(a)):\n", + " print a[i],\n", + " print ''\n", + " \n", + "a = [55.5, 22.5, 99.9, 66.6, 44.4, 88.8, 33.3, 77.7]\n", + "\n", + "print_(a)\n", + "sort(a,8)\n", + "print_(a)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "55.5 22.5 99.9 66.6 44.4 88.8 33.3 77.7 \n", + "22.5 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.14, page no. 135" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def index(x,a,n):\n", + " # PRECONDITION: a[0] <= a[1] <= ... <= a[n-1];\n", + " # binary search:\n", + " lo=0\n", + " hi=n-1\n", + " while (lo <= hi):\n", + " i = (lo + hi)/2 # the average of lo and hi\n", + " if (a[i] == x):\n", + " return i\n", + " if (a[i] < x):\n", + " lo = i+1 # continue search in a[i+1..hi]\n", + " else:\n", + " hi = i-1 # continue search in a[lo..i-1]\n", + " return n # x was not found in a[0..n-1]\n", + "\n", + "a = [ 22, 33, 44, 55, 66, 77, 88 ]\n", + "print \"index(44,a,7) = \" , index(44,a,7)\n", + "print \"index(60,a,7) = \" , index(60,a,7) \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "index(44,a,7) = 2\n", + "index(60,a,7) = 7\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.15, page no. 136" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def isNondecreasing(a,n):\n", + " # returns true iff a[0] <= a[1] <= ... <= a[n-1]:\n", + " for i in range(1,n):\n", + " if (a[i]\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m \u001b[1;36m22\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m33\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m55\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m66\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m77\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m88\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 35\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(44,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 36\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(44,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 37\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(60,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m60\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mindex\u001b[1;34m(x, a, n)\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;31m# PRECONDITION: a[0] <= a[1] <= ... <= a[n-1];\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;31m# binary search:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 20\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0misNondecreasing\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 21\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 22\u001b[0m \u001b[0mlo\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mAssertionError\u001b[0m: " + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "index(44,a,7) = 2\n", + "index(44,a,7) = " + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.17, page no. 137" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "Day = [ 0, 1, 2, 3, 4, 5, 6 ]\n", + "high = [ 88.3, 95.0, 91.2, 89.9, 91.4, 92.5, 86.7]\n", + "\n", + "for i in Day:\n", + " print \"The high temperature for day \" , i , \" was \" , high[i] \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The high temperature for day 0 was 88.3\n", + "The high temperature for day 1 was 95.0\n", + "The high temperature for day 2 was 91.2\n", + "The high temperature for day 3 was 89.9\n", + "The high temperature for day 4 was 91.4\n", + "The high temperature for day 5 was 92.5\n", + "The high temperature for day 6 was 86.7\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.18, page no. 139" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def sort(a,n):\n", + " a.sort()\n", + "\n", + "def print_(a,n):\n", + " for i in a:\n", + " print i,\n", + " print ''\n", + "a = [55.5, 22.5, 99.9, 66.6, 44.4, 88.8, 33.3, 77.7]\n", + "print_(a,8);\n", + "sort(a,8)\n", + "print_(a,8)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "55.5 22.5 99.9 66.6 44.4 88.8 33.3 77.7 \n", + "22.5 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.19, page no. 139" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def read(a):\n", + " print \"Enter 15 integers, 5 per row:\\n\"\n", + " for i in range(3):\n", + " ar = []\n", + " print \"Row \" , i , \": \",\n", + " for j in range(5):\n", + " ar.append(int(raw_input()))\n", + " a.append(ar)\n", + "\n", + "def print_(a):\n", + " for i in range(3):\n", + " for j in range(5):\n", + " print a[i][j],\n", + " print ''\n", + "a = []\n", + "read(a)\n", + "print_(a)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 15 integers, 5 per row:\n", + "\n", + "Row 0 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "11\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Row 1 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "60\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "50\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "30\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "90\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "70\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Row 2 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "85\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "55\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 44 77 33 11 44 \n", + "60 50 30 90 70 \n", + "85 25 45 45 55 \n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.20, page no. 140" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def read(score):\n", + " for s in range(3):\n", + " print \"Student \" , s , \": \",\n", + " st = []\n", + " for q in range(5):\n", + " st.append(int(raw_input()))\n", + " score.append(st)\n", + "\n", + "def printQuizAverages(score):\n", + " for s in range(3):\n", + " sm = 0\n", + " for q in range(5):\n", + " sm += score[s][q]\n", + " print \"\\tStudent \" , s , \": \" , sm/5.0\n", + "\n", + "def printClassAverages(score):\n", + " for q in range(5):\n", + " sm = 0\n", + " for s in range(3):\n", + " sm += score[s][q]\n", + " print \"\\tQuiz \" , q , \": \" , sm/3.0\n", + "\n", + "\n", + "\n", + "NUM_STUDENTS = 3\n", + "NUM_QUIZZES = 5\n", + "\n", + "\n", + "score = []\n", + "print \"Enter \" , NUM_QUIZZES , \" scores for each student: \"\n", + "read(score)\n", + "print \"The quiz averages are:\"\n", + "printQuizAverages(score)\n", + "print \"The class averages are: \"\n", + "printClassAverages(score)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 5 scores for each student: \n", + "Student 0 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Student 1 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " Student 2 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " The quiz averages are:\n", + "\tStudent 0 : 8.2\n", + "\tStudent 1 : 8.8\n", + "\tStudent 2 : 7.0\n", + "The class averages are: \n", + "\tQuiz 0 : 7.33333333333\n", + "\tQuiz 1 : 7.33333333333\n", + "\tQuiz 2 : 8.33333333333\n", + "\tQuiz 3 : 8.33333333333\n", + "\tQuiz 4 : 8.66666666667\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.21, page no. 141" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def numZeros(a,n1,n2,n3):\n", + " count = 0\n", + " for i in range(n1):\n", + " for j in range(n2):\n", + " for k in range(n3):\n", + " if (a[i][j][k] == 0):\n", + " count += 1\n", + " return count\n", + "\n", + "\n", + "a = [ [ [5,0,2], [0,0,9], [4,1,0], [7,7,7] ],[ [3,0,0], [8,5,0], [0,0,0], [2,0,9] ]]\n", + "print \"This array has \" , numZeros(a,2,4,3) , \" zeros\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "This array has 11 zeros\n" + ] + } + ], + "prompt_number": 25 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch7.ipynb b/Schaum's_Outline/ch7.ipynb new file mode 100755 index 00000000..63248e07 --- /dev/null +++ b/Schaum's_Outline/ch7.ipynb @@ -0,0 +1,750 @@ +{ + "metadata": { + "name": "ch7" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Capter 7: Pointers and References" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.1, Page no: 157" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "n=44\n", + "print \"n = \" , n \n", + "# prints the value of n\n", + "print \"&n = \" , hex(id(n)) # prints the address of n\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 44\n", + "&n = 0x8fc0eec\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.2, Page no: 157" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : Python doesn't support reference/pointer variable. But can be achieved by using mutable datatypes i.e. list.\n", + "'''\n", + "\n", + "\n", + "n = [44]\n", + "rn=n # r is a synonym for n\n", + "print \"n = \" , n , \", rn = \" , rn \n", + "n[0] -= 1\n", + "print \"n = \" , n , \", rn = \" , rn \n", + "rn[0] *= 2\n", + "print \"n = \" , n , \", rn = \" , rn \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = [44] , rn = [44]\n", + "n = [43] , rn = [43]\n", + "n = [86] , rn = [86]\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.3, Page no: 158" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "n = [44]\n", + "rn=n # r is a synonym for n\n", + "print \"&n = \" , hex(id(n)) , \", rn = \" , hex(id(rn ))\n", + "rn2 = n\n", + "rn3 = rn\n", + "print \"&rn2 = \" , hex(id(rn2)) , \", rn = \" , hex(id(rn ))\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "&n = 0x9c6228c , rn = 0x9c6228c\n", + "&rn2 = 0x9c6228c , rn = 0x9c6228c\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.4, Page no: 159" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "n = [44]\n", + "print \"n = \" , n , \", &n = \" , hex(id(n))\n", + "pn = n\n", + "print \"pn = \" , hex(id(pn)) , \", &pn = \" , hex(id(hex(id(pn))))\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = [44] , &n = 0x9c624ec\n", + "pn = 0x9c624ec , &pn = 0x9c6aa60\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.5, Page no: 159" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "n = [44]\n", + "print \"n = \" , n , \", &n = \" , hex(id(n))\n", + "pn = n\n", + "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", + "print \"*pn = \" , pn\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = [44] , &n = 0x9c58d6c\n", + "\tpn = 0x9c58d6c ,\n", + " &pn = 0x9c6ab20\n", + "*pn = [44]\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.6, Page no: 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "n = [44]\n", + "print \"n = \" , n , \", &n = \" , hex(id(n))\n", + "pn = n\n", + "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", + "print \"*pn = \" , pn\n", + "ppn = pn\n", + "\n", + "print \" ppn = \" , hex(id(hex(id(ppn)))) \n", + "print \" &ppn = \" , hex(id(hex(id(hex(id(ppn))))))\n", + "print \" *ppn = \" , hex(id(ppn)) \n", + "print \"**ppn = \" , ppn \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = [44] , &n = 0x9bf05ac\n", + "\tpn = 0x9bf05ac ,\n", + " &pn = 0x9c58160\n", + "*pn = [44]\n", + " ppn = 0x9c58680\n", + " &ppn = 0x9c58160\n", + " *ppn = 0x9bf05ac\n", + "**ppn = [44]\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.7, Page no: 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "n = [44]\n", + "print \"n = \" , n , \"\\n &n = \" , hex(id(n))\n", + "pn = n\n", + "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", + "print \"*pn = \" , pn\n", + "nn = pn\n", + "print \" ppn = \" , hex(id(nn))\n", + "print \" &ppn = \" , hex(id(hex(id(nn))))\n", + "rpn = pn\n", + "print \" ppn = \" , hex(id(rpn))\n", + "print \" &ppn = \" , hex(id(hex(id(rpn))))\n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = [44] \n", + " &n = 0x9bf60ec\n", + "\tpn = 0x9bf60ec ,\n", + " &pn = 0x9bf0e40\n", + "*pn = [44]\n", + " ppn = 0x9bf60ec\n", + " &ppn = 0x9bf0e40\n", + " ppn = 0x9bf60ec\n", + " &ppn = 0x9bf0f20\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.8, Page no: 162" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def max_(m,n):\n", + " if m>n:\n", + " return m\n", + " else:\n", + " return n\n", + "\n", + "m = 44\n", + "n = 22\n", + "print m , \", \" , n , \", \" , max_(m,n)\n", + "m = max_(m,n) \n", + "m = 55\n", + "# changes the value of m from 44 to 55\n", + "print m , \", \" , n , \", \" , max_(m,n) \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "44 , 22 , 44\n", + "55 , 22 , 55\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.9, Page no: 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "v = []\n", + "for k in range(1,5):\n", + " v.append(1.0/k)\n", + "\n", + "for i in range(4):\n", + " print \"v[\" , i , \"] = \" , v[i]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "v[ 0 ] = 1.0\n", + "v[ 1 ] = 0.5\n", + "v[ 2 ] = 0.333333333333\n", + "v[ 3 ] = 0.25\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.10, Page no: 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import sys\n", + "a = [22, 33, 44]\n", + "\n", + "print \"a = \" , hex(id(a))\n", + "print \"sizeof(int) = \" , sys.getsizeof(1) \n", + "s = 0\n", + "for i in a:\n", + " s += i\n", + " print \"\\t i = \" , hex(id(i)),\n", + " print \"\\t *i = \" , i,\n", + " print \"\\t sum = \" , s\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 0x9bf688c\n", + "sizeof(int) = 12\n", + "\t i = 0x8fc0ff4 \t *i = 22 \t sum = 22\n", + "\t i = 0x8fc0f70 \t *i = 33 \t sum = 55\n", + "\t i = 0x8fc0eec \t *i = 44 \t sum = 99\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.11, Page no: 165" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "a = [22, 33, 44, 55, 66]\n", + "print \"a = \" , hex(id(a)) , \", *a = \" , a[0] \n", + "for p in a:\n", + " print \"p = \" , hex(id(p)) , \", *p = \" , p \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a = 0x9c6526c , *a = 22\n", + "p = 0x8fc0ff4 , *p = 22\n", + "p = 0x8fc0f70 , *p = 33\n", + "p = 0x8fc0eec , *p = 44\n", + "p = 0x8fc0e68 , *p = 55\n", + "p = 0x8fc0de4 , *p = 66\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.12, Page no: 165" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def loc(a1,a2,n1,n2):\n", + " p = []\n", + " for element in a2:\n", + " if element in a1:\n", + " p.append(element)\n", + " return p\n", + "\n", + "a1 = [11, 11, 11, 11, 11, 22, 33, 44, 55]\n", + "a2 = [11, 11, 11, 22, 33]\n", + "print \"Array a1 begins at location\\t\" , hex(id(a1 ))\n", + "print \"Array a2 begins at location\\t\" , hex(id(a2)) \n", + "p = loc(a1, a2, 9, 5)\n", + "if (p):\n", + " print \"Array a2 found at location\\t\" , hex(id(p))\n", + " for i in range(len(p)):\n", + " print \"\\t\" , hex(id(p[i])) , \": \" , p[i], \"\\t\" , hex(id(a2[i])) , \": \" , a2[i] \n", + "else:\n", + " print \"Not found.\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Array a1 begins at location\t0x9bea56c\n", + "Array a2 begins at location\t0x9bea62c\n", + "Array a2 found at location\t0x9bea6cc\n", + "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", + "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", + "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", + "\t0x8fc0ff4 : 22 \t0x8fc0ff4 : 22\n", + "\t0x8fc0f70 : 33 \t0x8fc0f70 : 33\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.13, Page no: 166" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def get(a):\n", + " print \"Enter number of items: \"\n", + " n = int(raw_input())\n", + " print \"Enter \" , n , \" items, one per line:\"\n", + " for i in range(n):\n", + " print \"\\t\" , i+1 , \": \",\n", + " a.append(float(raw_input()))\n", + "\n", + "def print_(a):\n", + " for i in range(len(a)):\n", + " print a[i] ,\n", + " print ''\n", + "\n", + "a = []\n", + "get(a)\n", + "print_(a)\n", + "a = []\n", + "get(a)\n", + "print_(a)\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter number of items: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 4 items, one per line:\n", + "\t1 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44.4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t2 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "77.7\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t3 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "22.2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t4 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "88.8\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 44.4 77.7 22.2 88.8 \n", + "Enter number of items: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "2\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 2 items, one per line:\n", + "\t1 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "3.33\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " \t2 : " + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "9.99\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " 3.33 9.99 \n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.14, Page no: 167" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def sort(p, n):\n", + " for i in range(1,n):\n", + " for j in range(n-i):\n", + " if (p[j] > p[j+1]):\n", + " p[j],p[j+1] = p[j+1],p[j]\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.15, Page no: 168" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def sum_(k,n):\n", + " # returns the sum f(0) + f(1) + f(2) + . . . + f(n-1):\n", + " s = 0\n", + " for i in range(1,n+1):\n", + " s += k(i)\n", + " return s\n", + "\n", + "def square(k):\n", + " return k*k\n", + "\n", + "def cube(k):\n", + " return k*k*k\n", + "\n", + "\n", + "print sum_(square,4) # 1 + 4 + 9 + 16\n", + "print sum_(cube,4) # 1 + 8 + 27 + 64\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "30\n", + "100\n" + ] + } + ], + "prompt_number": 15 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch8.ipynb b/Schaum's_Outline/ch8.ipynb new file mode 100755 index 00000000..2b83cace --- /dev/null +++ b/Schaum's_Outline/ch8.ipynb @@ -0,0 +1,1064 @@ +{ + "metadata": { + "name": "ch8" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 8: C- Strings" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.1, page no. 184" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "n= [44] # n holds the int 44\n", + "print \"int n=44; // n holds the int 44:\\n\";\n", + "print \"\\t\\t n = \" , n \n", + "print \"\\t\\t &n = \" , hex(id(n))\n", + "pn = n \n", + "print \"int* pn=&n; // pn holds the address of n:\\n\";\n", + "print \"\\t\\t n = \" , n \n", + "print \"\\t\\t &n = \" , hex(id(n))\n", + "print \"\\t\\t pn = \" , hex(id(pn)) \n", + "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", + "print \"\\t\\t *pn = \" , pn\n", + "\n", + "pn[0] = 77 # changes the value of n to 77\n", + "print \"*pn = 77; // changes the value of n to 77:\\n\";\n", + "print \"\\t\\t n = \" , n \n", + "print \"\\t\\t &n = \" , hex(id(n))\n", + "print \"\\t\\t pn = \" , hex(id(pn)) \n", + "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", + "print \"\\t\\t *pn = \" , pn\n", + "\n", + "q = n \n", + "print \"int* q=&n; // q also holds the address of n:\\n\";\n", + "print \"\\t\\t n = \" , n \n", + "print \"\\t\\t &n = \" , hex(id(n))\n", + "print \"\\t\\t pn = \" , hex(id(pn)) \n", + "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", + "print \"\\t\\t *pn = \" , pn\n", + "print \"\\t\\t q = \" , hex(id(q))\n", + "print \"\\t\\t &q = \" , hex(id(hex(id(hex(id(pn))))))\n", + "print \"\\t\\t *q = \" , q \n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "int n=44; // n holds the int 44:\n", + "\n", + "\t\t n = [44]\n", + "\t\t &n = 0x9bfb92c\n", + "int* pn=&n; // pn holds the address of n:\n", + "\n", + "\t\t n = [44]\n", + "\t\t &n = 0x9bfb92c\n", + "\t\t pn = 0x9bfb92c\n", + "\t\t &pn = 0x9bf5aa0\n", + "\t\t *pn = [44]\n", + "*pn = 77; // changes the value of n to 77:\n", + "\n", + "\t\t n = [77]\n", + "\t\t &n = 0x9bfb92c\n", + "\t\t pn = 0x9bfb92c\n", + "\t\t &pn = 0x9c6a760\n", + "\t\t *pn = [77]\n", + "int* q=&n; // q also holds the address of n:\n", + "\n", + "\t\t n = [77]\n", + "\t\t &n = 0x9bfb92c\n", + "\t\t pn = 0x9bfb92c\n", + "\t\t &pn = 0x9bf5c80\n", + "\t\t *pn = [77]\n", + "\t\t q = 0x9bfb92c\n", + "\t\t &q = 0x9c6a760\n", + "\t\t *q = [77]\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.2, page no. 185" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s = \"ABCD\"\n", + "for i in range(4):\n", + " print \"s[\" , i , \"] = '\" , s[i] , \"'\\n\";\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "s[ 0 ] = ' A '\n", + "\n", + "s[ 1 ] = ' B '\n", + "\n", + "s[ 2 ] = ' C '\n", + "\n", + "s[ 3 ] = ' D '\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.3, page no. 186" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "while True:\n", + " word = raw_input()\n", + " if len(word) < 2:\n", + " break\n", + " l = word.split(' ')\n", + " for i in l:\n", + " print '\\t\"' , i , '\"'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Today's date is March 12, 2000.\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t\" Today's \"\n", + "\t\" date \"\n", + "\t\" is \"\n", + "\t\" March \"\n", + "\t\" 12, \"\n", + "\t\" 2000. \"\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Tomorrow is Monday.\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t\" Tomorrow \"\n", + "\t\" is \"\n", + "\t\" Monday. \"\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.4, page no. 187" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "while True:\n", + " line = raw_input()\n", + " if len(line) < 2:\n", + " break\n", + " print \"\\t[\" , line , \"]\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Once upon a midnight dreary, while I pondered, weak and weary,\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t[ Once upon a midnight dreary, while I pondered, weak and weary, ]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Over a many quaint and curious volume of forgotten lore,\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t[ Over a many quaint and curious volume of forgotten lore, ]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.5, page no. 187" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "while True:\n", + " word = raw_input()\n", + " if len(word) < 2:\n", + " break\n", + " l = word.split(',')\n", + " for i in range(len(l)-1):\n", + " print '\\t[' , l[i] , ']'\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Once upon a midnight dreary, while I pondered, weak and weary,\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t[ Once upon a midnight dreary ]\n", + "\t[ while I pondered ]\n", + "\t[ weak and weary ]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Over a many quaint and curious volume of forgotten lore,\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t[ Over a many quaint and curious volume of forgotten lore ]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.6, page no. 188" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "count = 0\n", + "while True:\n", + " a = raw_input()\n", + " if len(a) < 1:\n", + " break\n", + " for ch in a:\n", + " if (ch == 'e'): count+=1\n", + " \n", + "print count , \" e's were counted.\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Once upon a midnight dreary, while I pondered, weak and weary,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Over many a quaint and curious volume of forgotten lore,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "11 e's were counted.\n", + "\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.7, page no. 188" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "while True:\n", + " a = raw_input()\n", + " if len(a) < 1:\n", + " break\n", + " print a.title()\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Fourscore and seven years ago our fathers\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Fourscore And Seven Years Ago Our Fathers\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "brought forth upon this continent a new nation,\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Brought Forth Upon This Continent A New Nation,\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.8, page no. 189" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "a = raw_input()\n", + "l = a.split(' ')\n", + "nos = []\n", + "for i in l:\n", + " try:\n", + " i = int(i)\n", + " nos.append(i)\n", + " except:\n", + " continue\n", + "m = nos[0]\n", + "n = nos[1] \n", + "print m , \" + \" , n , \" = \" , m+n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "what is 305 plus 9416 ?\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "305 + 9416 = 9721\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.10, page no. 191" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "count=0\n", + "\n", + "print \"Enter at most 4 names with at most 19 characters:\\n\";\n", + "while (True):\n", + " n = raw_input()\n", + " if len(n) < 1:\n", + " break\n", + " name.append(n)\n", + " count += 1\n", + " \n", + "print \"The names are:\\n\"\n", + "for i in range(count):\n", + " print \"\\t\" , i , \". [\" , name[i] , \"]\" \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter at most 4 names with at most 19 characters:\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "George Washington\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "John Adams\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thomas Jefferson\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The names are:\n", + "\n", + "\t0 . [ George Washington ]\n", + "\t1 . [ John Adams ]\n", + "\t2 . [ Thomas Jefferson ]\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.11, page no. 192" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "name = []\n", + "count=0\n", + "\n", + "print \"Enter at most 4 names with at most 19 characters:\\n\";\n", + "while (True):\n", + " n = raw_input()\n", + " if len(n) < 1:\n", + " break\n", + " name.append(n)\n", + " count += 1\n", + " \n", + "print \"The names are:\\n\"\n", + "for i in range(count):\n", + " print \"\\t\" , i , \". [\" , name[i] , \"]\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter at most 4 names with at most 19 characters:\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "George Washington\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "John Adams\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thomas Jefferson\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The names are:\n", + "\n", + "\t0 . [ George Washington ]\n", + "\t1 . [ John Adams ]\n", + "\t2 . [ Thomas Jefferson ]\n" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.12, page no. 193" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "name = [ \"George Washington\", \"John Adams\", \"Thomas Jefferson\"]\n", + "print \"The names are:\\n\"\n", + "for i in range(3):\n", + " print \"\\t\" , i , \". [\" , name[i] , \"]\"\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The names are:\n", + "\n", + "\t0 . [ George Washington ]\n", + "\t1 . [ John Adams ]\n", + "\t2 . [ Thomas Jefferson ]\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.13, page no. 193" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s = \"ABCDEFG\"\n", + "print \"len(\" , s , \") = \" , len(s) \n", + "print \"len(\\\"\\\") = \" , len(\"\")\n", + "print \"Enter string: \"\n", + "b = raw_input()\n", + "print \"len(\" , b , \") = \" , len(b)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "len( ABCDEFG ) = 7\n", + "len(\"\") = 0\n", + "Enter string: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello how are you !!!\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "len( hello how are you !!! ) = 21\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.14, page no. 194" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s = \"The Mississippi is a long river.\"\n", + "print 's = \"' , s , '\"'\n", + "p = s.find(' ')\n", + "print \"find(s, ' ') points to s[\" , p , \"].\"\n", + "p = s.find('s')\n", + "print \"find(s, 's') points to s[\" , p , \"].\"\n", + "p = s.rfind('s')\n", + "print \"reverse find(s, 's') points to s[\" , p , \"].\"\n", + "p = s.find(\"is\")\n", + "print \"strstr(s, \\\"is\\\") points to s[\" , p , \"].\"\n", + "p = s.find(\"isi\")\n", + "if p== -1:\n", + " print 's.find(\"isi\") returns NULL'\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "s = \" The Mississippi is a long river. \"\n", + "find(s, ' ') points to s[ 3 ].\n", + "find(s, 's') points to s[ 6 ].\n", + "reverse find(s, 's') points to s[ 17 ].\n", + "strstr(s, \"is\") points to s[ 5 ].\n", + "s.find(\"isi\") returns NULL\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.15, page no. 195" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s1 = \"ABCDEFG\"\n", + "s2 = \"XYZ\" \n", + "print \"Before strcpy(s1,s2):\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", + "s1 = s2\n", + "print \"After strcpy(s1,s2):\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Before strcpy(s1,s2):\n", + "\n", + "\ts1 = [ ABCDEFG ], length = 7\n", + "\ts2 = [ XYZ ], length = 3\n", + "After strcpy(s1,s2):\n", + "\n", + "\ts1 = [ XYZ ], length = 3\n", + "\ts2 = [ XYZ ], length = 3\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.16, page no. 195" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s1 = \"ABCDEFG\"\n", + "s2 = \"XYZ\" \n", + "print \"Before strcpy(s1,s2,2):\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", + "s1 = s2[:2] + s1[2:]\n", + "print \"After strcpy(s1,s2,2):\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", + "\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Before strcpy(s1,s2,2):\n", + "\n", + "\ts1 = [ ABCDEFG ], length = 7\n", + "\ts2 = [ XYZ ], length = 3\n", + "After strcpy(s1,s2,2):\n", + "\n", + "\ts1 = [ XYCDEFG ], length = 7\n", + "\ts2 = [ XYZ ], length = 3\n" + ] + } + ], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.17, page no. 196" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s1 = \"ABCDEFG\"\n", + "s2 = \"XYZ\" \n", + "print \"Before string concatination :\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", + "s1 += s2\n", + "print \"After string concatination :\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Before string concatination :\n", + "\n", + "\ts1 = [ ABCDEFG ], length = 7\n", + "\ts2 = [ XYZ ], length = 3\n", + "After string concatination :\n", + "\ts1 = [ ABCDEFGXYZ ], length = 10\n", + "\ts2 = [ XYZ ], length = 3\n" + ] + } + ], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.18, page no. 197" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s1 = \"ABCDEFG\"\n", + "s2 = \"XYZ\" \n", + "print \"Before string concatination :\\n\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", + "s1 += s2[:2]\n", + "print \"After string concatination :\" \n", + "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", + "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Before string concatination :\n", + "\n", + "\ts1 = [ ABCDEFG ], length = 7\n", + "\ts2 = [ XYZ ], length = 3\n", + "After string concatination :\n", + "\ts1 = [ ABCDEFGXY ], length = 9\n", + "\ts2 = [ XYZ ], length = 3\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.19, page no. 197" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "s = \"Today's date is March 12, 2000.\"\n", + "\n", + "print \"The string is: [\" , s , \"] \\nIts tokens are: \"\n", + "p = s.split(\" \")\n", + "\n", + "for i in p:\n", + " print \"\\t[\" , i , \"] \"\n", + "\n", + "print \"Now the string is: [\" , p[0] , \"] \";\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The string is: [ Today's date is March 12, 2000. ] \n", + "Its tokens are: \n", + "\t[ Today's ] \n", + "\t[ date ] \n", + "\t[ is ] \n", + "\t[ March ] \n", + "\t[ 12, ] \n", + "\t[ 2000. ] \n", + "Now the string is: [ Today's ] \n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 8.20, page no. 199" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def strpbrk(s,s1):\n", + " found = []\n", + " for i in range(len(s1)):\n", + " if s1[i] in s:\n", + " index = s.find(s1[i])\n", + " found.append(index)\n", + " if found:\n", + " return min(found)\n", + " return None\n", + " \n", + "\n", + "s = \"The Mississippi is a long river.\"\n", + "print 's = \"' , s , '\"'\n", + "p = strpbrk(s, \"nopqr\")\n", + "print 'strpbrk(s, \"nopqr\") points to s[' , p , \"].\"\n", + "p = strpbrk(s, \"NOPQR\")\n", + "if (p == None):\n", + " print 'strpbrk(s, \"NOPQR\") returns NULL.\\n'" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "s = \" The Mississippi is a long river. \"\n", + "strpbrk(s, \"nopqr\") points to s[ 12 ].\n", + "strpbrk(s, \"NOPQR\") returns NULL.\n", + "\n" + ] + } + ], + "prompt_number": 22 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/ch9.ipynb b/Schaum's_Outline/ch9.ipynb new file mode 100755 index 00000000..d8416ec9 --- /dev/null +++ b/Schaum's_Outline/ch9.ipynb @@ -0,0 +1,444 @@ +{ + "metadata": { + "name": "ch9" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 9: Standard C++ strings" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.2, Page no: 214" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "while True:\n", + " try:\n", + " n = int(raw_input())\n", + " print \"n = \" , n \n", + " except:\n", + " break" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "46\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 46\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "22\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 22\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "44\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "66\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 66\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "88\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "n = 88\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "33,\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.4, Page no: 215" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "king = [] # defines king to be an array \n", + "n=0\n", + "while True:\n", + " name = raw_input()\n", + " if len(name) < 1:\n", + " break\n", + " king.append(name)\n", + " n += 1\n", + "# now n == the number of names read\n", + "for i in range(n):\n", + " print '\\t' , i+1 , \". \" , king[i] " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Kenneth II (971-995)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Constantine III (995-997)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Kenneth III (997-1005)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Malcolm II (1005-1034)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Duncan I (1034-1040)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Macbeth (1040-1057)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Lulach (1057-1058)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Malcolm III (1058-1093)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\t1 . Kenneth II (971-995)\n", + "\t2 . Constantine III (995-997)\n", + "\t3 . Kenneth III (997-1005)\n", + "\t4 . Malcolm II (1005-1034)\n", + "\t5 . Duncan I (1034-1040)\n", + "\t6 . Macbeth (1040-1057)\n", + "\t7 . Lulach (1057-1058)\n", + "\t8 . Malcolm III (1058-1093)\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.6, Page no: 217" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Note : you need input.txt in same directory for the program to run without any errors.\n", + "'''\n", + "\n", + "infile = open(\"input.txt\",\"r\")\n", + "outfile = open(\"output.txt\",\"w\")\n", + "\n", + "for i in infile:\n", + " s = i.title()\n", + " outfile.write(s)\n", + "\n", + "infile.close()\n", + "outfile.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "IOError", + "evalue": "[Errno 2] No such file or directory: 'input.txt'", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[0;32m 6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0minfile\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"input.txt\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0moutfile\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"output.txt\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"w\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'input.txt'" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.7, Page no: 218" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''Note: You need the files - north.dat, south.dat, combined.dat in the same directory for the program to run without any errors'''\n", + "\n", + "fin1 = open(\"north.dat\",\"r\")\n", + "fin2 = open(\"south.dat\",\"r\")\n", + "fout = open(\"combined.dat\",\"w\")\n", + "\n", + "file1 = []\n", + "file2 = []\n", + "for i in fin1:\n", + " try:\n", + " s = i.split(\" \")\n", + " for j in s:\n", + " file1.append(int(j))\n", + " except:\n", + " continue\n", + " \n", + "for i in fin2:\n", + " try:\n", + " s = i.split(\" \")\n", + " for j in s:\n", + " file2.append(int(j))\n", + " except:\n", + " continue\n", + "\n", + "\n", + "for i in sorted(file1 + file2):\n", + " fout.write(str(i) + \" \")\n", + "\n", + "fin1.close()\n", + "fin2.close()\n", + "fout.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "IOError", + "evalue": "[Errno 2] No such file or directory: 'north.dat'", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m '''\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mfin1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"north.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mfin2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"south.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mfout\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"combined.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"w\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'north.dat'" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.8, Page no: 219" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def print_(oss):\n", + " print 'oss.str() = \"' , str(oss) , '\"'\n", + "\n", + "s=\"ABCDEFG\"\n", + "n=33\n", + "x=2.718\n", + "l = ''\n", + "print_(l)\n", + "l += s\n", + "print_(l)\n", + "l += ( \" \" + str(n) )\n", + "print_(l)\n", + "l += ( \" \" + str(x) )\n", + "print_(l)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "oss.str() = \" \"\n", + "oss.str() = \" ABCDEFG \"\n", + "oss.str() = \" ABCDEFG 33 \"\n", + "oss.str() = \" ABCDEFG 33 2.718 \"\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 9.9, Page no: 220" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def print_(iss,s='',n=0,x=0.0):\n", + " print 's = \"' , s , '\", n = ' , n , \", x = \" , x, ', iss.str() = \"' \\\n", + " , iss , '\"' \n", + "\n", + "s=\"\"\n", + "n=0\n", + "x=0.0\n", + "l = ''\n", + "iss = \"ABCDEFG 44 3.14\"\n", + "print_(iss)\n", + "s = \"ABCDEFG\"\n", + "print_(iss,s)\n", + "n = 44\n", + "print_(iss,s,n)\n", + "x = 3.14\n", + "print_(iss,s,n,x)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "s = \" \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 44 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 44 , x = 3.14 , iss.str() = \" ABCDEFG 44 3.14 \"\n" + ] + } + ], + "prompt_number": 6 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Schaum's_Outline/screenshots/ratio.png b/Schaum's_Outline/screenshots/ratio.png new file mode 100755 index 00000000..68bb8cd0 Binary files /dev/null and b/Schaum's_Outline/screenshots/ratio.png differ diff --git a/Schaum's_Outline/screenshots/swap.png b/Schaum's_Outline/screenshots/swap.png new file mode 100755 index 00000000..7d707e37 Binary files /dev/null and b/Schaum's_Outline/screenshots/swap.png differ diff --git a/Schaum's_Outline/screenshots/vector.png b/Schaum's_Outline/screenshots/vector.png new file mode 100755 index 00000000..b51554ce Binary files /dev/null and b/Schaum's_Outline/screenshots/vector.png differ diff --git a/Schaum's_Outlines:_Programming_with_C++/README.txt b/Schaum's_Outlines:_Programming_with_C++/README.txt deleted file mode 100755 index 272f5329..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/README.txt +++ /dev/null @@ -1,10 +0,0 @@ -Contributed By: Hiren Shah -Course: mca -College/Institute/Organization: Financial Technology -Department/Designation: Developer -Book Title: Schaum's Outlines: Programming with C++ -Author: John R. Hubbard -Publisher: McGRAW-HILL -Year of publication: 2000 -Isbn: 0-07-135346-1. -Edition: 2nd \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch1.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch1.ipynb deleted file mode 100755 index 175e4501..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch1.ipynb +++ /dev/null @@ -1,448 +0,0 @@ -{ - "metadata": { - "name": "ch1" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 1: Elementary C++ Programming" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.1, page no. 2" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Hello, World!\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Hello, World!\n", - "\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.2, page no. 3" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "print \"Hello, World!\\n\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Hello, World!\n", - "\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.3, page no. 4" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "print \"Hel\" + \"lo, Wo\" + \"rld!\" " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Hello, World!\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.4, page no. 5" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "print \"Hello, W\" + 'o' + \"rld\" + '!' " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Hello, World!\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.5, page no. 5" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "print \"The Millennium ends Dec %d %d \" %(31,2000)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The Millennium ends Dec 31 2000 \n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.6, page no. 5" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "m = 44 # assigns the value 44 to the variable m\n", - "print \"m = %d \" % m,\n", - "n = m + 33 # assigns the value 77 to the variable n\n", - "print \"and n = %d \" % n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "m = 44 and n = 77 \n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.7, page no. 6" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "n=44\n", - "print \"n = %d\" % n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 44\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.8, page no. 7" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Python does not have semicolons so wont give any errors.\n", - "n=44\n", - "print \"n = %d\" % n " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 44\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.9, page no. 7" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "m = 0 #In python we do not have declaration of variables, we just initialize it and use it.\n", - "n=44\n", - "print \"m = %d and n = %d\" %(m,n)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "m = 0 and n = 44\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.10, page no. 8" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "BEEP = '\\b'\n", - "MAXINT = 2147483647\n", - "N = MAXINT/2\n", - "KM_PER_MI = 1.60934\n", - "PI = 3.14159265358979323846" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 1.11, page no. 8" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "print \"Enter two integers: \"\n", - "m = int(raw_input())\n", - "n = int(raw_input())\n", - "print \"m = %d , n = %d \" %(m,n)\n", - "\n", - "print \"Enter three decimal numbers: \"\n", - "x = float(raw_input())\n", - "y = float(raw_input())\n", - "z = float(raw_input())\n", - "\n", - "print \"x = %f , y = %f , z = %f\" %(x,y,z)\n", - "\n", - "print \"Enter four characters: \";\n", - "c1 = raw_input()\n", - "c2 = raw_input()\n", - "c3 = raw_input()\n", - "c4 = raw_input()\n", - "print \"c1 = \" + c1 + \", c2 = \" + c2 + \", c3 = \" + c3 + \", c4 = \" + c4 " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "22\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "m = 22 , n = 44 \n", - "Enter three decimal numbers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2.2\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4.4\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "6.6\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 2.200000 , y = 4.400000 , z = 6.600000\n", - "Enter four characters: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "A\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "B\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "C\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "D\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "c1 = A, c2 = B, c3 = C, c4 = D\n" - ] - } - ], - "prompt_number": 11 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch10.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch10.ipynb deleted file mode 100755 index eb3d1761..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch10.ipynb +++ /dev/null @@ -1,877 +0,0 @@ -{ - "metadata": { - "name": "ch10" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 10: Classes" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.1, Page no: 233" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self):\n", - " self.num = 0\n", - " self.den = 0\n", - " def assign(self,n,d):\n", - " self.num = n\n", - " self.den = d\n", - " def convert(self):\n", - " return float(self.num)/self.den\n", - " def invert(self):\n", - " self.num,self.den = self.den,self.num\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - " \n", - "x = Ratio()\n", - "x.assign(22,7)\n", - "print \"x = \",\n", - "x.print_()\n", - "print \" = \" , x.convert() \n", - "x.invert()\n", - "print \"1/x = \",\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 22 / 7 = 3.14285714286\n", - "1/x = 7 / 22\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.2, Page no: 234" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self):\n", - " self.num = 0\n", - " self.den = 0\n", - " def assign(self,n,d):\n", - " self.num = n\n", - " self.den = d\n", - " def convert(self):\n", - " return float(self.num)/self.den\n", - " def invert(self):\n", - " self.num,self.den = self.den,self.num\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.3, Page no: 235" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n,d):\n", - " self.num = n\n", - " self.den = d\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - "x = Ratio(-1,3)\n", - "y = Ratio(22,7)\n", - "print \"x = \",\n", - "x.print_()\n", - "print \" and y = \",\n", - "y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = -1 / 3 and y = 22 / 7\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.4, Page no: 236" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " elif d==None:\n", - " self.num = n\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - "x = Ratio()\n", - "y = Ratio(4)\n", - "z = Ratio(22,7)\n", - "print \"x = \",\n", - "x.print_()\n", - "print \"\\ny = \",\n", - "y.print_()\n", - "print \"\\nz = \",\n", - "z.print_()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 0 / 1 \n", - "y = 4 / 1 \n", - "z = 22 / 7\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.5, Page no: 237" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " elif d==None:\n", - " self.num = n\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.6, Page no: 237" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - "\n", - "x = Ratio()\n", - "y = Ratio(4)\n", - "z = Ratio(22,7)" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.7, Page no: 238" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " def numerator(self):\n", - " return self.num\n", - " def denominator(self):\n", - " return self.den\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - "\n", - "x = Ratio(22,7)\n", - "print x.numerator() , '/' , x.denominator() " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22 / 7\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.8, Page no: 238" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def numerator(self):\n", - " return self.num\n", - " def denominator(self):\n", - " return self.den\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(100,-360)\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "-5 / 18\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.9, Page no: 240" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=0,d=None):\n", - " if d == None:\n", - " self.num = n.num\n", - " self.den = n.den\n", - " else: \n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def numerator(self):\n", - " return self.num\n", - " def denominator(self):\n", - " return self.den\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(100,360)\n", - "y = Ratio(x)\n", - "print \"x = \",\n", - "x.print_()\n", - "print \"y = \",\n", - "y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 5 / 18 y = 5 / 18\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.10, Page no: 241" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=0,d=None):\n", - " if d == None:\n", - " print \"COPY CONSTRUCTOR CALLED\"\n", - " self.num = n.num\n", - " self.den = n.den\n", - " else: \n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def numerator(self):\n", - " return self.num\n", - " def denominator(self):\n", - " return self.den\n", - " def print_(self):\n", - " print self.num , '/' , self.den ,\n", - "\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "def f(r):\n", - " s = Ratio(r)\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(x) #calls the copy constructor, copying x to y\n", - "f(y)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "COPY CONSTRUCTOR CALLED\n", - "COPY CONSTRUCTOR CALLED\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.11, Page no: 242" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python objects die when program gets exit.\n", - "'''\n", - "\n", - "class Ratio:\n", - " def __init__(self):\n", - " print \"OBJECT IS BORN.\"\n", - " def __del__(self):\n", - " print \"OBJECT DIES.\"\n", - "\n", - "x = Ratio()\n", - "print \"Now x is alive.\"\n", - "print \"Now between blocks.\"\n", - "y = Ratio()\n", - "print \"Now y is alive.\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "OBJECT IS BORN.\n", - "Now x is alive.\n", - "Now between blocks.\n", - "OBJECT IS BORN.\n", - "Now y is alive.\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.12, Page no: 244" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class X:\n", - " def __init(self):\n", - " data = 0\n", - "\n", - "p = X()\n", - "p.data = 22\n", - "print \"p.data = \" , p.data , \" = \" , p.data\n", - "p.data = 44\n", - "print \" p.data = \" , p.data , \" = \" , p.data " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "p.data = 22 = 22\n", - " p.data = 44 = 44\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.13, Page no: 244" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Node:\n", - " def __init__(self,d,q=None):\n", - " self.data = d\n", - " self.next = q\n", - "\n", - "n = int(raw_input())\n", - "q = Node(n)\n", - "while True:\n", - " n = int(raw_input())\n", - " if n<=0:\n", - " break\n", - " p = Node(n, q)\n", - " q = p\n", - "k = p\n", - "while k != None:\n", - " print k.data , '->' , \n", - " k = k.next\n", - "print '*'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "22\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "66\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "77 -> 66 -> 55 -> 44 -> 33 -> 22 -> *\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.14, Page no: 246" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Python does not support static data type.\n", - "Python automatically handles local variable so we need not to delete it.\n", - "'''\n", - "count = 0\n", - "class Widget:\n", - " def __init__(self):\n", - " global count\n", - " count += 1\n", - " \n", - "w = Widget()\n", - "x = Widget()\n", - "print \"Now there are \" , count , 'widgets'\n", - "if True:\n", - " w = Widget()\n", - " x = Widget()\n", - " y = Widget()\n", - " z = Widget()\n", - " print \"Now there are\" , count , 'widgets' \n", - "print \"Now there are \" , count , 'widgets'\n", - "y = Widget()\n", - "print \"Now there are \" , count , 'widgets'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "OBJECT DIES.\n", - "Now there are 2 widgets\n", - "OBJECT DIES.\n", - "Now there are 6 widgets\n", - "Now there are 6 widgets\n", - "Now there are 7 widgets\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.15, Page no: 246" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "count = 0\n", - "class Widget:\n", - " def __init__(self):\n", - " global count\n", - " count += 1\n", - " def numWidgets(self):\n", - " global count\n", - " return count\n", - " \n", - "w = Widget()\n", - "x = Widget()\n", - "print \"Now there are \" , w.numWidgets() , 'widgets'\n", - "if True:\n", - " w = Widget()\n", - " x = Widget()\n", - " y = Widget()\n", - " z = Widget()\n", - " print \"Now there are\" , w.numWidgets() , 'widgets' \n", - "print \"Now there are \" , w.numWidgets() , 'widgets'\n", - "y = Widget()\n", - "print \"Now there are \" , w.numWidgets() , 'widgets'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Now there are 2 widgets\n", - "Now there are 6 widgets\n", - "Now there are 6 widgets\n", - "Now there are 7 widgets\n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 10.16, Page no: 247" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "count = 0\n", - "class Widget:\n", - " def __init__(self):\n", - " global count\n", - " count += 1\n", - " def numWidgets(self):\n", - " global count\n", - " return count\n", - " \n", - "w = Widget()\n", - "x = Widget()\n", - "print \"Now there are \" , w.numWidgets() , 'widgets'\n", - "if True:\n", - " w = Widget()\n", - " x = Widget()\n", - " y = Widget()\n", - " z = Widget()\n", - " print \"Now there are\" , w.numWidgets() , 'widgets' \n", - "print \"Now there are \" , w.numWidgets() , 'widgets'\n", - "y = Widget()\n", - "print \"Now there are \" , w.numWidgets() , 'widgets'" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Now there are 2 widgets\n", - "Now there are 6 widgets\n", - "Now there are 6 widgets\n", - "Now there are 7 widgets\n" - ] - } - ], - "prompt_number": 18 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch11.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch11.ipynb deleted file mode 100755 index 321fb35b..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch11.ipynb +++ /dev/null @@ -1,793 +0,0 @@ -{ - "metadata": { - "name": "ch11" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 11: Overloading Operators" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.1, Page no: 256" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if d==None:\n", - " self.num = n.num\n", - " self.den = n.den\n", - " elif n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " \n", - " def equals(self):\n", - " return self # retuns calling object." - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.2, Page no: 257" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " pass\n", - " \n", - " def equals(self):\n", - " pass\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.3, Page no: 256" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if d==None:\n", - " self.num = n.num\n", - " self.den = n.den\n", - " elif n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " \n", - "\n", - "z = Ratio(22,7)\n", - "y = z\n", - "x = z\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(x)\n", - "z = x\n", - "w = x" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.4, Page no: 259" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " def __mul__(self,y):\n", - " pass\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.5, Page no: 259" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "x = Ratio(22,7)\n", - "y = Ratio(-3,8)\n", - "z = x\n", - "z.print_()\n", - "x = y*z\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22 / 7\n", - "-33 / 28\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.6, Page no: 260" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def print_(self):\n", - " print self.num , '/', self.den" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.7, Page no: 260" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def __eq__(self,y):\n", - " return (x.num * y.den == y.num * x.den)\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.8, Page no: 261" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "''' \n", - "Python does not use << operator for printing. So here we are just declaring function name as print_.\n", - "'''\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def __eq__(self,y):\n", - " return (x.num * y.den == y.num * x.den)\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - "\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(-3,8)\n", - "x.print_() , y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22 / 7\n", - "-3 / 8\n" - ] - }, - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 8, - "text": [ - "(None, None)" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.9, Page no: 262" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Python does not have >> for input. so we will use input function.\n", - "'''\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def input(self):\n", - " self.num = int(raw_input('Numerator : '))\n", - " self.den = int(raw_input('Denominator : '))\n", - " self.reduce()\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "\n", - "x = Ratio()\n", - "y = Ratio()\n", - "x.input()\n", - "y.input()\n", - "x.print_()\n", - "y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Numerator : -10\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Denominator : -24\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Numerator : 36\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Denominator : -20\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "5 / 12\n", - "-9 / 5\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.10, Page no: 263" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def input(self):\n", - " self.num = int(raw_input('Numerator : '))\n", - " self.den = int(raw_input('Denominator : '))\n", - " self.reduce()\n", - " def __float__(self):\n", - " return float(self.num)/self.den\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 15.py\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(-5,8)\n", - "print \"x = \" , \n", - "x.print_() \n", - "print \", float(x) = \" , float(x) \n", - "P = Ratio(22,7)\n", - "PI = float(P)\n", - "print \"P = \" ,\n", - "P.print_() \n", - "print \", PI = \" , PI\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = -5 / 8\n", - ", float(x) = -0.625\n", - "P = 22 / 7\n", - ", PI = 3.14285714286\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.11, Page no: 264" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __iadd__(self,n):\n", - " self.num += self.den\n", - " return self\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "x += 1\n", - "y = x\n", - "print \"y = \" ,\n", - "y.print_()\n", - "print \", x = \",\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "y = 29 / 7\n", - ", x = 29 / 7\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.12, Page no: 265" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __iadd__(self,n):\n", - " self.num += self.den\n", - " return self\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(x.num,x.den)\n", - "x += 1\n", - "print \"y = \" ,\n", - "y.print_()\n", - "print \", x = \",\n", - "x.print_()\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "y = 22 / 7\n", - ", x = 29 / 7\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 11.13, Page no:266" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " # returns the greatest common divisor of m and n:\n", - " if (m0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __getitem__(self,k):\n", - " if k == 1:\n", - " return self.num\n", - " else:\n", - " return self.den\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "print \"x = \" ,\n", - "x.print_()\n", - "print \"x[1] = \" , x[1] , \", x[2] = \" , x[2]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 22 / 7\n", - "x[1] = 22 , x[2] = 7\n" - ] - } - ], - "prompt_number": 7 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch12.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch12.ipynb deleted file mode 100755 index 2743b6a5..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch12.ipynb +++ /dev/null @@ -1,869 +0,0 @@ -{ - "metadata": { - "name": "ch12" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 12: Composition and Inheritance" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.1, Page no: 273" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Person:\n", - " def __init__(self,n=\"\",nat=\"U.S.A.\",s=1):\n", - " self.name = n\n", - " self.nationality = nat\n", - " self.sex = s\n", - "\n", - " def printName(self):\n", - " print self.name,\n", - " \n", - " def printNationality(self):\n", - " print self.nationality,\n", - "\n", - "creator = Person(\"Bjarne Stroustrup\", \"Denmark\")\n", - "print \"The creator of C++ was \" ,\n", - "creator.printName() \n", - "print \", who was born in \" ,\n", - "creator.printNationality() \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The creator of C++ was Bjarne Stroustrup , who was born in Denmark\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.2, Page no: 274" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Date:\n", - " def __init__(self,m=0,d=0,y=0):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " \n", - " def setDate(self,m,d,y):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " # Python doesn't have >> operator for input so we are just using input function\n", - " def input(self):\n", - " self.month = int(raw_input()) \n", - " self.day = int(raw_input())\n", - " self.year = int(raw_input()) \n", - " \n", - " # Python doesn't have << operator for output so we are just using print function\n", - " def print_(self):\n", - " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", - " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", - " \"December\"]\n", - " print monthName[self.month] , self.day , \",\" , self.year\n", - "\n", - "peace = Date(11,11,1918)\n", - "print \"World War I ended on \" ,\n", - "peace.print_()\n", - "peace.setDate(8,14,1945)\n", - "print \"World War II ended on \" ,\n", - "peace.print_()\n", - "print \"Enter month, day, and year: \"\n", - "date = Date()\n", - "date.input()\n", - "print \"The date is \" , \n", - "date.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "World War I ended on November 11 , 1918\n", - "World War II ended on August 14 , 1945\n", - "Enter month, day, and year: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "7\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "1976\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The date is July 4 , 1976\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.3, Page no: 274" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Date:\n", - " def __init__(self,m=0,d=0,y=0):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " \n", - " def setDate(self,m,d,y):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " # Python doesn't have >> operator for input so we are just using input function\n", - " def input(self):\n", - " self.month = int(raw_input()) \n", - " self.day = int(raw_input())\n", - " self.year = int(raw_input()) \n", - " \n", - " # Python doesn't have << operator for output so we are just using print function\n", - " def print_(self):\n", - " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", - " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", - " \"December\"]\n", - " print monthName[self.month] , self.day , \",\" , self.year\n", - "\n", - "class Person:\n", - " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", - " self.name = n\n", - " self.nationality = nat\n", - " self.sex = s\n", - " self.dob = Date()\n", - " self.dod = Date()\n", - " def setDOB(self,m,d,y):\n", - " self.dob.setDate(m,d,y)\n", - " def setDOD(self,m,d,y):\n", - " self.dod.setDate(m,d,y)\n", - " def printName(self):\n", - " print self.name,\n", - " def printNationality(self):\n", - " print self.nationality,\n", - " def printDOB(self):\n", - " self.dob.print_()\n", - " def printDOD(self):\n", - " self.dod.print_()\n", - "\n", - "author = Person(\"Thomas Jefferson\", 1)\n", - "author.setDOB(4,13,1743)\n", - "author.setDOD(7,4,1826)\n", - "print \"The author of the Declaration of Independence was \",\n", - "author.printName()\n", - "print \".\\nHe was born on \",\n", - "author.printDOB()\n", - "print \" and died on \",\n", - "author.printDOD()\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The author of the Declaration of Independence was Thomas Jefferson .\n", - "He was born on April 13 , 1743\n", - " and died on July 4 , 1826\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.4, Page no: 276" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Date:\n", - " def __init__(self,m=0,d=0,y=0):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " \n", - " def setDate(self,m,d,y):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " # Python doesn't have >> operator for input so we are just using input function\n", - " def input(self):\n", - " self.month = int(raw_input()) \n", - " self.day = int(raw_input())\n", - " self.year = int(raw_input()) \n", - " \n", - " # Python doesn't have << operator for output so we are just using print function\n", - " def print_(self):\n", - " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", - " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", - " \"December\"]\n", - " print monthName[self.month] , self.day , \",\" , self.year\n", - "\n", - "class Person:\n", - " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", - " self.name = n\n", - " self.nationality = nat\n", - " self.sex = s\n", - " self.dob = Date()\n", - " self.dod = Date()\n", - " def setDOB(self,m,d,y):\n", - " self.dob.setDate(m,d,y)\n", - " def setDOD(self,m,d,y):\n", - " self.dod.setDate(m,d,y)\n", - " def printName(self):\n", - " print self.name,\n", - " def printNationality(self):\n", - " print self.nationality,\n", - " def printDOB(self):\n", - " self.dob.print_()\n", - " def printDOD(self):\n", - " self.dod.print_()\n", - "\n", - "class Student(Person):\n", - " def __init__(self,n,s=0,i=\"\"):\n", - " Person.__init__(self,n,s)\n", - " self.id = i\n", - " self.credits = 0\n", - " self.gpa = 0\n", - " self.dom = Date()\n", - "\n", - " def setDOM(self,m,d,y):\n", - " self.dom.setDate(m, d, y)\n", - " def printDOM(self):\n", - " self.dom.print_()\n", - "\n", - "x = Student(\"Ann Jones\", 0, \"219360061\")\n", - "x.setDOB(5, 13, 1977)\n", - "x.setDOM(8, 29, 1995)\n", - "x.printName()\n", - "print \"\\n\\t Born: \" ,\n", - "x.printDOB()\n", - "print \"\\n\\tMatriculated: \",\n", - "x.printDOM()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Ann Jones \n", - "\t Born: May 13 , 1977\n", - "\n", - "\tMatriculated: August 29 , 1995\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.5, Page no: 276" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Date:\n", - " def __init__(self,m=0,d=0,y=0):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " \n", - " def setDate(self,m,d,y):\n", - " self.month = m\n", - " self.day = d\n", - " self.year = y\n", - " # Python doesn't have >> operator for input so we are just using input function\n", - " def input(self):\n", - " self.month = int(raw_input()) \n", - " self.day = int(raw_input())\n", - " self.year = int(raw_input()) \n", - " \n", - " # Python doesn't have << operator for output so we are just using print function\n", - " def print_(self):\n", - " monthName = [\"\", \"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\\\n", - " \"July\", \"August\",\"September\", \"October\", \"November\",\\\n", - " \"December\"]\n", - " print monthName[self.month] , self.day , \",\" , self.year\n", - "\n", - "class Person:\n", - " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", - " self.name = n\n", - " self.nationality = nat\n", - " self.sex = s\n", - " self.dob = Date()\n", - " self.dod = Date()\n", - " def setDOB(self,m,d,y):\n", - " self.dob.setDate(m,d,y)\n", - " def setDOD(self,m,d,y):\n", - " self.dod.setDate(m,d,y)\n", - " def printName(self):\n", - " print self.name,\n", - " def printNationality(self):\n", - " print self.nationality,\n", - " def printDOB(self):\n", - " self.dob.print_()\n", - " def printDOD(self):\n", - " self.dod.print_()\n", - "\n", - "class Student(Person):\n", - " def __init__(self,n,s=0,i=\"\"):\n", - " Person.__init__(self,n,s)\n", - " self.id = i\n", - " self.credits = 0\n", - " self.gpa = 0\n", - " self.dom = Date()\n", - "\n", - " def setDOM(self,m,d,y):\n", - " self.dom.setDate(m, d, y)\n", - " def printDOM(self):\n", - " self.dom.print_()\n", - " def printSex(self):\n", - " if self.sex == 1:\n", - " print \"male\"\n", - " else:\n", - " print 'female'\n", - "\n", - "x = Student(\"Ann Jones\", 0, \"219360061\")\n", - "x.setDOB(5, 13, 1977)\n", - "x.setDOM(8, 29, 1995)\n", - "x.setDOD(7,4,1826)\n", - "x.printName()\n", - "print \"\\n\\t Born: \" , \n", - "x.printDOB()\n", - "print \"\\n\\t Sex: \" ,\n", - "x.printSex()\n", - "print \"\\n\\tMatriculated: \",\n", - "x.printDOM()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Ann Jones \n", - "\t Born: May 13 , 1977\n", - "\n", - "\t Sex: female\n", - "\n", - "\tMatriculated: August 29 , 1995\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.6, Page no: 279" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class X:\n", - " def __init__(self):\n", - " self.a = 0\n", - " def f(self):\n", - " print \"X::f() executing\"\n", - "class Y(X):\n", - " def __init__(self):\n", - " self.a = 0\n", - " def f(self):\n", - " print \"Y::f() executing\"\n", - "x = X()\n", - "x.a = 22\n", - "x.f()\n", - "print \"x.a = \" , x.a\n", - "y = Y()\n", - "y.a = 44\n", - "# assigns 44 to the a defined in Y\n", - "y._X__a = 66\n", - "# assigns 66 to the a defined in X\n", - "y.f()\n", - "# invokes the f() defined in Y\n", - "X.f(x)\n", - "# invokes the f() defined in X\n", - "print \"y.a = \" , y.a \n", - "print \"y._X__a = \" , y._X__a \n", - "z = y\n", - "print \"z.a = \" , z._X__a \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "X::f() executing\n", - "x.a = 22\n", - "Y::f() executing\n", - "X::f() executing\n", - "y.a = 44\n", - "y._X__a = 66\n", - "z.a = 66\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.7, Page no: 280" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python destuctor is called when program goes exit. So output may be differ than c.\n", - "'''\n", - "class X:\n", - " def __init__(self):\n", - " print \"X::X() constructor executing \"\n", - " def __del__(self):\n", - " print \"X::X() destructor executing \"\n", - "\n", - "class Y(X):\n", - " def __init__(self):\n", - " X.__init__(self)\n", - " print \"Y::Y() constructor executing \"\n", - " def __del__(self):\n", - " print \"Y::Y() destructor executing \"\n", - "\n", - "class Z(Y):\n", - " def __init__(self,i):\n", - " Y.__init__(self)\n", - " print \"Z::Z(\" , i , \") constructor executing \"\n", - " def __del__(self):\n", - " print \"Z::Z() destructor executing \"\n", - " \n", - "\n", - "Z = Z(44)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "X::X() constructor executing \n", - "Y::Y() constructor executing \n", - "Z::Z( 44 ) constructor executing \n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.8, Page no: 281" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python destuctor is called when program goes exit. So output may be differ than c.\n", - "'''\n", - "class Person:\n", - " def __init__(self,s):\n", - " self.name = s\n", - " def __del__(self):\n", - " pass\n", - "\n", - "class Student(Person):\n", - " def __init__(self,s,m):\n", - " Person.__init__(self,s)\n", - " self.major = m\n", - " def __del__(self):\n", - " pass\n", - "x = Person(\"Bob\")\n", - "y = Student(\"Sarah\", \"Biology\")\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.9, Page no: 282" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Person:\n", - " def __init__(self,n=\"\",s=0,nat=\"U.S.A.\"):\n", - " self.name = n\n", - " self.nationality = nat\n", - " self.sex = s\n", - " self.dob = Date()\n", - " self.dod = Date()\n", - " def setDOB(self,m,d,y):\n", - " self.dob.setDate(m,d,y)\n", - " def setDOD(self,m,d,y):\n", - " self.dod.setDate(m,d,y)\n", - " def printName(self):\n", - " print self.name,\n", - " def printNationality(self):\n", - " print self.nationality,\n", - " def printDOB(self):\n", - " self.dob.print_()\n", - " def printDOD(self):\n", - " self.dod.print_()\n", - " def setHSgraduate(self,g):\n", - " self.hs = g\n", - " def isHSgraduate(self):\n", - " return hs\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.10, Page no: 283" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : By default all methods in python are virtual. so output would be differ than c.\n", - "'''\n", - "class X:\n", - " def f(self):\n", - " print \"X::f() executing\"\n", - "class Y(X):\n", - " def f(self):\n", - " print \"Y::f() executing\"\n", - "x = X()\n", - "y = Y()\n", - "p = x\n", - "p.f()\n", - "p = y\n", - "p.f()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "X::f() executing\n", - "Y::f() executing\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.11, Page no: 284" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Person:\n", - " def __init__(self,n):\n", - " self.name = n\n", - " def print_(self):\n", - " print 'My name is' , self.name\n", - "\n", - "class Student(Person):\n", - " def __init__(self,s,g):\n", - " Person.__init__(self,s)\n", - " self.gpa = g\n", - " def print_(self):\n", - " print 'My name is ',self.name, ' and my G.P.A. is', self.gpa\n", - "\n", - "class Professor(Person):\n", - " def __init__(self,s,n):\n", - " Person.__init__(self,s)\n", - " self.publs = n\n", - " def print_(self):\n", - " print 'My name is ', self.name,' and i have ' , self.publs,' publications.'\n", - "\n", - "x = Person(\"Bob\")\n", - "p = x\n", - "p.print_()\n", - "y = Student(\"Tom\", 3.47)\n", - "p = y\n", - "p.print_()\n", - "z = Professor(\"Ann\", 7)\n", - "p = z\n", - "p.print_()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "My name is Bob\n", - "My name is Tom and my G.P.A. is 3.47\n", - "My name is Ann and i have 7 publications.\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.12, Page no: 285" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "This program is similar to Example 12.6:\n", - "'''\n", - "class X:\n", - " def __init__(self):\n", - " self.p = [0,0]\n", - " print 'X().',\n", - " def __del__(self):\n", - " print '~X().'\n", - "\n", - "class Y(X):\n", - " def __init__(self):\n", - " X.__init__(self)\n", - " self.q = []\n", - " for i in range(1023):\n", - " self.q.append(0)\n", - " print 'Y() : Y::q = ', hex(id(self.q)) ,'.',\n", - " def __del__(self):\n", - " print '~Y().'\n", - "\n", - "for i in range(8):\n", - " r = Y()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", - "X(). Y() : Y::q = 0x90c944c . ~Y().\n", - "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", - "X(). Y() : Y::q = 0x90c944c . ~Y().\n", - "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", - "X(). Y() : Y::q = 0x90c944c . ~Y().\n", - "X(). Y() : Y::q = 0x90d91cc . ~Y().\n", - "X(). Y() : Y::q = 0x90c944c . ~Y().\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 12.13, Page no: 288" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Media:\n", - " def __init__(self):\n", - " self.title = ''\n", - " def print_(self):\n", - " pass\n", - " def id(self):\n", - " pass\n", - "\n", - "class Book(Media):\n", - " def __init__(self,a='',t=\"\",p=\"\",i=\"\"):\n", - " self.author = a\n", - " self.publisher = p\n", - " self.isbn = i\n", - " self.title = t\n", - " def print_(self):\n", - " print self.title , \" by \" , self.author\n", - " def id(self):\n", - " return self.isbn\n", - "\n", - "class CD(Media):\n", - " def __init__(self,t=\"\",c=\"\",m=\"\",n=\"\"):\n", - " self.composer = c\n", - " self.make = m\n", - " self.number = n\n", - " self.title = t\n", - " def print_(self):\n", - " print self.title , \", \" , self.composer\n", - " def id(self):\n", - " s = str(self.make) + ' ' + str(self.number)\n", - " return s\n", - "\n", - "class Magazine(Media):\n", - " def __init__(self,t=\"\",i=\"\",v=0, n=0):\n", - " self.issn = i\n", - " self.volume = v\n", - " self.number = n\n", - " self.title = t\n", - " def print_(self):\n", - " print self.title , \" Magazine, Vol. \", self.volume , \", No.\" , self.number\n", - " def id(self):\n", - " return self.issn\n", - "\n", - "book = Book(\"Bjarne Stroustrup\", \"The C++ Programming Language\",\"Addison-Wesley\", \"0-201-53992-6\")\n", - "magazine = Magazine(\"TIME\", \"0040-781X\", 145, 23)\n", - "cd = CD(\"BACH CANTATAS\", \"Johann Sebastian Bach\",\"ARCHIV\", \"D120541\")\n", - "book.print_()\n", - "print \"\\tid: \" , book.id() \n", - "magazine.print_()\n", - "print \"\\tid: \" , magazine.id() \n", - "cd.print_()\n", - "print \"\\tid: \" , cd.id()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The C++ Programming Language by Bjarne Stroustrup\n", - "\tid: 0-201-53992-6\n", - "TIME Magazine, Vol. 145 , No. 23\n", - "\tid: 0040-781X\n", - "BACH CANTATAS , Johann Sebastian Bach\n", - "\tid: ARCHIV D120541\n" - ] - } - ], - "prompt_number": 14 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch13.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch13.ipynb deleted file mode 100755 index eea108dd..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch13.ipynb +++ /dev/null @@ -1,426 +0,0 @@ -{ - "metadata": { - "name": "ch13" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 13: Templates and Iterators" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.1, Page no: 300" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def swap(x,y):\n", - " x[0],y[0] = y[0],x[0]\n", - "\n", - "m = [22]\n", - "n = [66]\n", - "swap(m, n)\n", - "s1 = [\"John Adams\"]\n", - "s2 = [\"James Madison\"]\n", - "swap(s1, s2)\n", - "x = [22/7]\n", - "y = [-3]\n", - "swap(x, y)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.2, Page no: 301" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def sort(v,n):\n", - " for i in range(1,n):\n", - " for j in range(n-i):\n", - " if v[j] > v[j+1]:\n", - " v[j],v[j+1] = v[j+1],v[j]\n", - "\n", - "def print_( v,n):\n", - " for i in range(n):\n", - " print v[i],\n", - " print \"\"\n", - " \n", - "a = [55, 33, 88, 11, 44, 99, 77, 22, 66]\n", - "print_(a,9);\n", - "sort(a,9)\n", - "print_(a,9)\n", - "s = [\"Tom\", \"Hal\", \"Dan\", \"Bob\", \"Sue\", \"Ann\", \"Gus\"]\n", - "print_(s,7)\n", - "sort(s,7)\n", - "print_(s,7)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "55 33 88 11 44 99 77 22 66 \n", - "11 22 33 44 55 66 77 88 99 \n", - "Tom Hal Dan Bob Sue Ann Gus \n", - "Ann Bob Dan Gus Hal Sue Tom \n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.3, Page no: 303" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Stack:\n", - " def __init__(self,s=100):\n", - " self.size = s\n", - " self.top = -1\n", - " self.data = []\n", - " def push(self,x):\n", - " self.data.append( x)\n", - " self.top += 1\n", - " def pop(self):\n", - " d = self.data[self.top]\n", - " self.data.pop(self.top)\n", - " self.top -= 1\n", - " return d \n", - " def isEmpty(self):\n", - " return self.top == -1\n", - " def isFull(self):\n", - " return self.top==self.size-1\n", - " \n", - "intStack1 = Stack(5)\n", - "intStack2 = Stack(10)\n", - "charStack = Stack(8)\n", - "intStack1.push(77)\n", - "charStack.push('A')\n", - "intStack2.push(22)\n", - "charStack.push('E')\n", - "charStack.push('K')\n", - "intStack2.push(44)\n", - "print intStack2.pop() \n", - "print intStack2.pop() \n", - "if (intStack2.isEmpty()):\n", - " print \"intStack2 is empty.\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n", - "22\n", - "intStack2 is empty.\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.4, Page no: 305" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "= operator does work in python by defaultly.\n", - "'''\n", - "class Vector:\n", - " def __init__(self,n=None):\n", - " if type(n) == int :\n", - " self.size = n\n", - " self.data = []\n", - " else:\n", - " self.size = 8\n", - " self.data = []\n", - " for i in range(self.size):\n", - " self.data.append(0)\n", - "v = Vector()\n", - "v.data[5] = 127\n", - "w = v\n", - "x = Vector(3)\n", - "print w.size\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.5, Page no: 306" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Vector:\n", - " def __init__(self,n=None):\n", - " if type(n) == int :\n", - " self.size = n\n", - " self.data = []\n", - " else:\n", - " self.size = 8\n", - " self.data = []\n", - " for i in range(self.size):\n", - " self.data.append(0)\n", - "\n", - "class Array(Vector):\n", - " def __init__(self,i,j):\n", - " Vector.__init__(self,j-i+1)\n", - " self.i0= i\n", - " def __setitem__(self,k,v):\n", - " self.data[k-self.i0] = v\n", - " def __getitem__(self,i):\n", - " return self.data[self.i0-i]\n", - " def firstSubscript(self):\n", - " return self.i0\n", - " def lastSubscript(self):\n", - " return self.i0+self.size-1\n", - "\n", - "x = Array(1,3)\n", - "x.data[0] = 3.14159\n", - "x.data[1] = 0.08516\n", - "x.data[2] = 5041.92\n", - "print \"x.size() = \" , x.size \n", - "print \"x.firstSubscript() = \" , x.firstSubscript() \n", - "print \"x.lastSubscript() = \" , x.lastSubscript()\n", - "for i in range(0,3):\n", - " print \"x[\" , i + 1 , \"] = \" , x.data[i]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x.size() = 3\n", - "x.firstSubscript() = 1\n", - "x.lastSubscript() = 3\n", - "x[ 1 ] = 3.14159\n", - "x[ 2 ] = 0.08516\n", - "x[ 3 ] = 5041.92\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.6, Page no: 308" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Matrix:\n", - " def __init__(self,r=1,c=1):\n", - " self.rows = r\n", - " self.columns = c\n", - " self.vector = []\n", - " for i in range(r):\n", - " a = []\n", - " for j in range(c):\n", - " a.append(0)\n", - " self.vector.append(a)\n", - "\n", - "a = Matrix(2,3)\n", - "a.vector[0][0] = 0.0\n", - "a.vector[0][1] = 0.1\n", - "a.vector[0][2] = 0.2\n", - "a.vector[1][0] = 1.0\n", - "a.vector[1][1] = 1.1\n", - "a.vector[1][2] = 1.2\n", - "\n", - "print \"The matrix a has \" , a.rows , \" rows and \", a.columns , \" columns:\"\n", - "for i in range(2):\n", - " for j in range(3):\n", - " print a.vector[i][j] ,\n", - " print \"\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The matrix a has 2 rows and 3 columns:\n", - "0.0 0.1 0.2 \n", - "1.0 1.1 1.2 \n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.7, Page no: 309" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "friends = []\n", - "\n", - "\n", - "friends.insert(0,\"Bowen, Van\")\n", - "friends.insert(0,\"Dixon, Tom\")\n", - "friends.insert(0,\"Mason, Joe\")\n", - "friends.insert(0,\"White, Ann\")\n", - "\n", - "for i in range(len(friends)):\n", - " print friends[i], '->' ,\n", - "print '*'\n", - "friends.remove('White, Ann')\n", - "print \"Removed: \" , 'White, Ann'\n", - "for i in range(len(friends)):\n", - " print friends[i], '->' ,\n", - "print '*'\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "White, Ann -> Mason, Joe -> Dixon, Tom -> Bowen, Van -> *\n", - "Removed: White, Ann\n", - "Mason, Joe -> Dixon, Tom -> Bowen, Van -> *\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 13.8, Page no: 313" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "friends = []\n", - "friends.append(\"Bowen, Van\")\n", - "friends.append(\"Dixon, Tom\")\n", - "friends.append(\"Mason, Joe\")\n", - "friends.append(\"White, Ann\")\n", - "for i in range(len(friends)):\n", - " print friends[i], '->' ,\n", - "print '*'\n", - "\n", - "friends.remove(\"Mason, Joe\")\n", - "friends[1] = \"Davis, Jim\"\n", - "for i in range(len(friends)):\n", - " print friends[i], '->' ,\n", - "print '*'\n", - "\n", - "friends.insert(2,\"Morse, Sam\")\n", - "for i in range(len(friends)):\n", - " print friends[i], '->' ,\n", - "print '*'\n", - "\n", - "for i in range(len(friends)):\n", - " print \"[\" ,friends[i] , \"]\" , '->' ,\n", - "print '*'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Bowen, Van -> Dixon, Tom -> Mason, Joe -> White, Ann -> *\n", - "Bowen, Van -> Davis, Jim -> White, Ann -> *\n", - "Bowen, Van -> Davis, Jim -> Morse, Sam -> White, Ann -> *\n", - "[ Bowen, Van ] -> [ Davis, Jim ] -> [ Morse, Sam ] -> [ White, Ann ] -> *\n" - ] - } - ], - "prompt_number": 8 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch14.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch14.ipynb deleted file mode 100755 index 457669dc..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch14.ipynb +++ /dev/null @@ -1,616 +0,0 @@ -{ - "metadata": { - "name": "ch14" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 14: Standard C++ Vectors" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.1, Page no: 324" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.2, Page no: 325" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.3, Page no: 326" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in range(len(v)):\n", - " print v[i]\n", - "\n", - "v = []\n", - "load(v)\n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.4, Page no: 326" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "v.sort()\n", - "print_(v)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Chile\n", - "Egypt\n", - "Italy\n", - "Japan\n", - "Kenya\n", - "Nepal\n", - "Spain\n", - "Zaire\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.5, Page no: 327" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "w = v\n", - "print_(v)\n", - "print_(w)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n", - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.6, Page no: 327" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "v.sort()\n", - "print_(v)\n", - "print \"v.front() = \" + v[0]\n", - "print \"v.back() = \" + v.pop(-1) \n", - "print \"v.back() = \" + v.pop(-1) \n", - "print \"v.back() = \" + v[-1] \n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Chile\n", - "Egypt\n", - "Italy\n", - "Japan\n", - "Kenya\n", - "Nepal\n", - "Spain\n", - "Zaire\n", - "v.front() = Chile\n", - "v.back() = Zaire\n", - "v.back() = Spain\n", - "v.back() = Nepal\n", - "Chile\n", - "Egypt\n", - "Italy\n", - "Japan\n", - "Kenya\n", - "Nepal\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.7, Page no: 328" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "v.sort()\n", - "print_(v)\n", - "v.pop(2) # removes Italy\n", - "v.pop(-2) # removes Spain\n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Chile\n", - "Egypt\n", - "Italy\n", - "Japan\n", - "Kenya\n", - "Nepal\n", - "Spain\n", - "Zaire\n", - "Chile\n", - "Egypt\n", - "Japan\n", - "Kenya\n", - "Nepal\n", - "Zaire\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.8, Page no: 329" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "v = []\n", - "load(v)\n", - "v.sort()\n", - "print_(v)\n", - "r = []\n", - "for i in range(2,len(v)-2):\n", - " r.append(v[i]) #removes the segment Italy..Nepal\n", - " \n", - "for i in r:\n", - " v.remove(i)\n", - "print_(v)\n", - "v.insert(2,\"India\")\n", - "print_(v)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Chile\n", - "Egypt\n", - "Italy\n", - "Japan\n", - "Kenya\n", - "Nepal\n", - "Spain\n", - "Zaire\n", - "Chile\n", - "Egypt\n", - "Spain\n", - "Zaire\n", - "Chile\n", - "Egypt\n", - "India\n", - "Spain\n", - "Zaire\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.9, Page no: 329" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def load(v):\n", - " v.append(\"Japan\")\n", - " v.append(\"Italy\")\n", - " v.append(\"Spain\")\n", - " v.append(\"Egypt\")\n", - " v.append(\"Chile\")\n", - " v.append(\"Zaire\")\n", - " v.append(\"Nepal\")\n", - " v.append(\"Kenya\")\n", - " v.append(\"India\")\n", - " v.append(\"China\")\n", - " v.append(\"Malta\")\n", - " v.append(\"Syria\")\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i\n", - "\n", - "v = []\n", - "load(v)\n", - "print_(v)\n", - "egypt = v.index('Egypt')\n", - "malta = v.index('Malta')\n", - "w = v[egypt:malta+1]\n", - "w.sort()\n", - "print_(w)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Japan\n", - "Italy\n", - "Spain\n", - "Egypt\n", - "Chile\n", - "Zaire\n", - "Nepal\n", - "Kenya\n", - "India\n", - "China\n", - "Malta\n", - "Syria\n", - "Chile\n", - "China\n", - "Egypt\n", - "India\n", - "Kenya\n", - "Malta\n", - "Nepal\n", - "Zaire\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 14.10, Page no: 329" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def copy(v,x,n):\n", - " for i in x:\n", - " v.append(i)\n", - "\n", - "def projection(v,b):\n", - " v_size = len(v)\n", - " w = []\n", - " for i in range(0,v_size):\n", - " if b[i]:\n", - " w.append(v[i])\n", - " return w\n", - "\n", - "def print_(v):\n", - " for i in v:\n", - " print i,\n", - " print ''\n", - "\n", - "x = [ 22.2, 33.3, 44.4, 55.5, 66.6, 77.7, 88.8, 99.9 ]\n", - "v = []\n", - "copy(v, x, 8)\n", - "y = [ False, True, False, True, True, True, False, True ]\n", - "b = []\n", - "copy(b, y, 8)\n", - "w = projection(v, b)\n", - "print_(v)\n", - "print_(w)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22.2 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n", - "33.3 55.5 66.6 77.7 99.9 \n" - ] - } - ], - "prompt_number": 10 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch2.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch2.ipynb deleted file mode 100755 index 8697f28c..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch2.ipynb +++ /dev/null @@ -1,740 +0,0 @@ -{ - "metadata": { - "name": "ch2" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Chapter 2: Fundamental Types" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.1, page no. 17" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "flag=False\n", - "print \"flag = %r\" % flag\n", - "flag = True\n", - "print \"flag = %r\" % flag" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "flag = False\n", - "flag = True\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.2, page no. 19" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "c='A'\n", - "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", - "c='t'\n", - "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", - "c='\\t' # the tab character\n", - "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n", - "c='!'\n", - "print \"c = \" + c + \", int(c) = %d\" % ord(c)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "c = A, int(c) = 65\n", - "c = t, int(c) = 116\n", - "c = \t, int(c) = 9\n", - "c = !, int(c) = 33\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.3, page no. 19" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import sys\n", - "# defines the constants SHRT_MIN, etc.\n", - "print 'maximum limit int : ',\n", - "print sys.maxint\n", - "print 'float info'\n", - "print sys.float_info" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "maximum limit int : 2147483647\n", - "float info\n", - "sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.4, page no. 21" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "m=54\n", - "n=20\n", - "print \"m = %d and n = %d\" %(m,n)\n", - "print \"m+n = %d\" % (m+n) # 54+20 = 74\n", - "print \"m-n = %d\" % (m-n) # 54-20 = 34\n", - "print \"m*n = %d\" % (m*n)# 54*20 = 1080\n", - "print \"m/n = %d\" % (m/n) # 54/20 = 2\n", - "print \"m modulo by n = %d\" % (m%n) # 54%20 = 14" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "m = 54 and n = 20\n", - "m+n = 74\n", - "m-n = 34\n", - "m*n = 1080\n", - "m/n = 2\n", - "m modulo by n = 14\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.5, page no. 21" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "m = 44\n", - "m += 1\n", - "n = m\n", - "print \"m = %d , n = %d\" %(m,n)\n", - "m = 44\n", - "n = m # the post-increment operator is applied to m\n", - "m += 1\n", - "print \"m = %d , n = %d\" %(m,n)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "m = 45 , n = 45\n", - "m = 45 , n = 44\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.6, page no. 22" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "n=22\n", - "print \"n = %d\" % n\n", - "n += 9 # adds 9 to n\n", - "print \"After n += 9, n = %d\" % n\n", - "n -= 5 # subtracts 5 from n\n", - "print \"After n -= 5, n = %d\" % n\n", - "n *= 2 # multiplies n by 3\n", - "print \"After n *= 2, n = %d\" % n \n", - "n /= 3 # divides n by 9\n", - "print \"After n /= 3, n = %d\" % n \n", - "n %= 7 # reduces n to the remainder from dividing by 4\n", - "print 'After n modulo by 7 n = %d' %n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 22\n", - "After n += 9, n = 31\n", - "After n -= 5, n = 26\n", - "After n *= 2, n = 52\n", - "After n /= 3, n = 17\n", - "After n modulo by 7 n = 3\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.7, page no. 23" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "x=54.0\n", - "y=20.0\n", - "print \"x = %f and y = %f\" %(x,y)\n", - "print \"x+y = %f\" %(x+y) # 54.0+20.0 = 74.0\n", - "print \"x-y = %f\" % (x-y) # 54.0-20.0 = 34.0\n", - "print \"x*y = %f\" %( x*y) # 54.0*20.0 = 1080.0\n", - "print \"x/y = %f\" % (x/y) # 54.0/20.0 = 2.7\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 54.000000 and y = 20.000000\n", - "x+y = 74.000000\n", - "x-y = 34.000000\n", - "x*y = 1080.000000\n", - "x/y = 2.700000\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.8, page no. 23s" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import sys\n", - "\n", - "print \"Number of bytes used:\\n\"\n", - "\n", - "print \" char: %d \" % sys.getsizeof('a')\n", - "print \" int : %d \" % sys.getsizeof(int(1))\n", - "print \" string : %d \" % sys.getsizeof(str('hellololdei'))\n", - "print \"float : %d\" % sys.getsizeof(float(1.1))" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Number of bytes used:\n", - "\n", - " char: 22 \n", - " int : 12 \n", - " string : 32 \n", - "float : 16\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.9, page no. 24" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import sys\n", - "\n", - "fbits = 8*sys.getsizeof(float(123))\n", - "\n", - "# each byte contains 8 bits\n", - "print \"float uses : %d bits:\\n\\t\" % fbits " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "float uses : 128 bits:\n", - "\t\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.10, page no. 25" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "v = 1234.56789\n", - "n = int(v);\n", - "print \"v = %f, n = %d\" %(v,n)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "v = 1234.567890, n = 1234\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.11, page no. 26" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "c='A'\n", - "print \"char c = \" + c\n", - "k=c;\n", - "print \"k = \" + k \n", - "m=k;\n", - "print \"m = \" + m \n", - "n=m\n", - "print \"n = \" + n\n", - "x=m\n", - "print \"x = \" + x \n", - "y=x\n", - "print \"y = \" + y" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "char c = A\n", - "k = A\n", - "m = A\n", - "n = A\n", - "x = A\n", - "y = A\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.12, page no. 27" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "n=1000\n", - "print \"n = %d\" % n\n", - "n *= 1000 # multiplies n by 1000\n", - "print \"n = %d\" % n\n", - "n *= 1000 # multiplies n by 1000\n", - "print \"n = %d\" % n\n", - "n *= 1000 # multiplies n by 1000\n", - "print \"n = %d\" % n\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 1000\n", - "n = 1000000\n", - "n = 1000000000\n", - "n = 1000000000000\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.13, page no. 27" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "x=1000.0\n", - "print \"x = %f\" % x\n", - "x *= x # multiplies n by itself; i.e., it squares x\n", - "print \"x = %f\" % x\n", - "x *= x # multiplies n by itself; i.e., it squares x\n", - "print \"x = %f\" % x\n", - "x *= x # multiplies n by itself; i.e., it squares x\n", - "print \"x = %f\" % x\n", - "x *= x # multiplies n by itself; i.e., it squares x\n", - "print \"x = %f\" % x\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 1000.000000\n", - "x = 1000000.000000\n", - "x = 1000000000000.000000\n", - "x = 999999999999999983222784.000000\n", - "x = 1000000000000000043845843045076197354634047651840.000000\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.14, page no. 28" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "x = 1000/3.0\n", - "print \"x = %f\" %x # x = 1000/3\n", - "y = x - 333.0\n", - "print \"y = %f\" % y # y = 1/3\n", - "z = 3*y - 1.0\n", - "print \"z = %f\" %z # z = 3(1/3) - 1\n", - "if (z == 0):\n", - " print \"z == 0.\\n\"\n", - "else:\n", - " print \"z does not equal 0.\\n\" # z != 0\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 333.333333\n", - "y = 0.333333\n", - "z = -0.000000\n", - "z does not equal 0.\n", - "\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.15, page no. 28" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "\n", - "\n", - "a = float(raw_input(\"Enter the coefficients of a quadratic equation:\\n a : \"))\n", - "b = float(raw_input('b : '))\n", - "c = float(raw_input('c : '))\n", - "\n", - "print \"The equation is: \",\n", - "print a,\n", - "print \"*x*x + \",\n", - "print b,\n", - "print \"*x + \" ,\n", - "print c,\n", - "print \" = 0\" \n", - "\n", - "d = b*b - 4*a*c # discriminant\n", - "sqrtd = math.sqrt(d)\n", - "x1 = (-b + sqrtd)/(2*a)\n", - "x2 = (-b - sqrtd)/(2*a)\n", - "print \"The solutions are:\"\n", - "print \"\\tx1 = %f\" % x1\n", - "print \"\\tx2 = %f\" % x2\n", - "print \"Check:\" \n", - "print \"\\ta*x1*x1 + b*x1 + c = %f\" %( a*x1*x1 + b*x1 + c)\n", - "print \"\\ta*x2*x2 + b*x2 + c = %f\" %( a*x2*x2 + b*x2 + c)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter the coefficients of a quadratic equation:\n", - " a : 2\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "b : 1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "c : -3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The equation is: 2.0 *x*x + 1.0 *x + -3.0 = 0\n", - "The solutions are:\n", - "\tx1 = 1.000000\n", - "\tx2 = -1.500000\n", - "Check:\n", - "\ta*x1*x1 + b*x1 + c = 0.000000\n", - "\ta*x2*x2 + b*x2 + c = 0.000000\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.17, page no. 31" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "x = float(raw_input(\"Enter float: \"))\n", - "print \"Its reciprocal is: \",\n", - "print 1/x " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter float: 234.567e89\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Its reciprocal is: 4.2631742743e-92\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.18, page no. 31" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "x = 11\n", - "# ERROR: this is not in the scope of x\n", - "if True:\n", - " x = 22 # OK: this is in the scope of x\n", - " y = 33 # ERROR: this is not in the scope of y\n", - " x = 44 # OK: this is in the scope of x\n", - " y = 55 # OK: this is in the scope of y\n", - "x = 66 # OK: this is in the scope of x\n", - "y = 77 # ERROR: this is not in the scope of y\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 2.19, page no. 32" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# this x is global\n", - "x = 11\n", - "\n", - "if True:\n", - " # illustrates the nested and parallel scopes:\n", - " x = 22\n", - " # begin scope of internal block\n", - " if True:\n", - " x = 33\n", - " print \"In block inside main(): x = %d \" % x\n", - " # end scope of internal block\n", - "print \"In main(): x = %d\" %x \n", - "print \"In main(): x = %d \"% x" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In block inside main(): x = 33 \n", - "In main(): x = 33\n", - "In main(): x = 33 \n" - ] - } - ], - "prompt_number": 18 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch3.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch3.ipynb deleted file mode 100755 index d023e19b..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch3.ipynb +++ /dev/null @@ -1,1153 +0,0 @@ -{ - "metadata": { - "name": "ch3" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 3: Selection" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.1, page no. 36" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two positive integers: \";\n", - "n = int(raw_input())\n", - "d = int(raw_input())\n", - "if (n%d):\n", - " print \"%d is not divisible by %d\" %(n,d)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two positive integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "66\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "7\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "66 is not divisible by 7\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.2, page no. 37" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two positive integers: \";\n", - "n = int(raw_input())\n", - "d = int(raw_input())\n", - "if (n%d):\n", - " print \"%d is not divisible by %d\" %(n,d)\n", - "else:\n", - " print \"%d is divisible by %d\" %(n,d)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two positive integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "56\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "7\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "56 is divisible by 7\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.3, page no. 38" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two integers: \"\n", - "m = int(raw_input())\n", - "n = int(raw_input())\n", - "\n", - "if (m < n):\n", - " print \"%d is the minimum.\" %m\n", - "else:\n", - " print \"%d is the minimum.\" %n\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "55 is the minimum.\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.4, page no. 38" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter an integer: \"\n", - "n = int(raw_input())\n", - "if (n = 22):\n", - " print \"%d = 22\" %n\n", - "else: \n", - " print \"%d != 22\" %n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 3)", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m if (n = 22):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.5, page no. 39" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter three integers: \"\n", - "n1 = int(raw_input())\n", - "n2 = int(raw_input())\n", - "n3 = int(raw_input())\n", - "\n", - "m=n1\n", - "# now min <= n1\n", - "if (n2 < m):\n", - " m = n2 # now min <= n1 and min <= n2\n", - "if (n3 < m):\n", - " m = n3 # now min <= n1, min <= n2, and min <= n3\n", - "print \"Their minimum is %d\" % m" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter three integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Their minimum is 33\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.6, page no. 39" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two integers: \"\n", - "x = int(raw_input())\n", - "y = int(raw_input())\n", - "\n", - "if (x > y):\n", - " temp=x\n", - " x = y\n", - " y = temp\n", - " \n", - "\n", - "print \"%d <= %d\" %(x,y)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "66\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "44 <= 66\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.7, page no. 40" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "n=44\n", - "print \"n = %d\" % n \n", - "if True:\n", - " # scope extends over 4 lines\n", - " print \"Enter an integer: \"\n", - " n = int(raw_input())\n", - " print \"n = %d\" % n \n", - "\n", - "if True:\n", - " print \"n = %d\" % n \n", - " # the n that was declared first\n", - "if True:\n", - " print \"n = %d\" % n \n", - "\n", - "print \"n = %d\" % n " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 44\n", - "Enter an integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 77\n", - "n = 77\n", - "n = 77\n", - "n = 77\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.8, page no. 41" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter three integers: \"\n", - "n1 = int(raw_input())\n", - "n2 = int(raw_input())\n", - "n3 = int(raw_input())\n", - "if (n1 <= n2 and n1 <= n3):\n", - " print \"Their minimum is %d\" % n1\n", - " \n", - "if (n2 <= n1 and n2 <= n3):\n", - " print \"Their minimum is %d \" % n2 \n", - "if (n3 <= n1 and n3 <= n2):\n", - " print \"Their minimum is %d\" % n3 \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter three integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Their minimum is 33 \n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.9, page no. 41" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Are you enrolled (y/n): \"\n", - "ans = raw_input()\n", - "if (ans == 'Y' or ans == 'y'):\n", - " print \"You are enrolled.\\n\"\n", - "else: \n", - " print \"You are not enrolled.\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Are you enrolled (y/n): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "y\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "You are enrolled.\n", - "\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.10, page no. 42" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "print \"Enter two positive integers: \";\n", - "n = int(raw_input())\n", - "d = int(raw_input())\n", - "\n", - "if (d != 0 and n%d == 0): \n", - " print \"%d divides %d\" %(d,n)\n", - "else:\n", - " print \"%d does not divide %d\"% (d,n)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two positive integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "6\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "6 does not divide 33\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.11, page no. 43" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter three integers: \"\n", - "n1 = int(raw_input())\n", - "n2 = int(raw_input())\n", - "n3 = int(raw_input())\n", - "\n", - "if (n1 >= n2 >= n3):\n", - " print \"max = x\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter three integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "1\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.12, page no. 43" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two positive integers: \"\n", - "n = int(raw_input())\n", - "d = int(raw_input())\n", - "\n", - "if (d != 0):\n", - " if (n%d == 0):\n", - " print d,\n", - " print \" divides %d\" % n \n", - " else:\n", - " print \"%d does not divide %d\" %(d,n)\n", - "else:\n", - " print '%d does not divide %d '%(d,n)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two positive integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "44 does not divide 55\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.13, page no. 44" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter three integers: \"\n", - "n1 = int(raw_input())\n", - "n2 = int(raw_input())\n", - "n3 = int(raw_input())\n", - "if (n1 < n2):\n", - " if (n1 < n3):\n", - " print \"Their minimum is : %d\" % n1\n", - " else:\n", - " print \"Their minimum is : %d\" % n3\n", - "else: # n1 >= n2\n", - " if (n2 < n3):\n", - " print \"Their minimum is : %d\" % n2\n", - " else:\n", - " print \"Their minimum is %d\" % n3" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter three integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Their minimum is : 33\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.14, page no. 44" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Pick a number from 1 to 8.\" \n", - "answer = int(raw_input())\n", - "print \"Is it less than 5? (y|n): \"\n", - "answer = raw_input()\n", - "if (answer == 'y'): # 1 <= n <= 4\n", - " print \"Is it less than 3? (y|n): \"\n", - " answer = raw_input() \n", - " if (answer == 'y'): # 1 <= n <= 2\n", - " print \"Is it less than 2? (y|n): \"\n", - " answer = raw_input()\n", - " if (answer == 'y'):\n", - " print \"Your number is 1.\"\n", - " else:\n", - " print \"Your number is 2.\"\n", - " else: # 3 <= n <= 4\n", - " print \"Is it less than 4? (y|n): \"\n", - " answer = raw_input()\n", - " if (answer == 'y'):\n", - " print \"Your number is 3.\"\n", - " else:\n", - " print \"Your number is 4.\"\n", - "else: # 5 <= n <= 8\n", - " print \"Is it less than 7? (y|n): \"\n", - " answer = raw_input()\n", - " if (answer == 'y'): # 5 <= n <= 6\n", - " print \"Is it less than 6? (y|n): \"\n", - " answer = raw_input()\n", - " if (answer == 'y'):\n", - " print \"Your number is 5.\"\n", - " else:\n", - " print \"Your number is 6.\" \n", - " else: # 7 <= n <= 8\n", - " print \"Is it less than 8? (y|n): \"\n", - " answer = raw_input()\n", - " if (answer == 'y'):\n", - " print \"Your number is 7.\" \n", - " else:\n", - " print \"Your number is 8.\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Pick a number from 1 to 8.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "6\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Is it less than 5? (y|n): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "n\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Is it less than 7? (y|n): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "y\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Is it less than 6? (y|n): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "n\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Your number is 6.\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.15, page no. 46" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "language = raw_input(\"Engl., Fren., Ger., Ital., or Rus.? (e|f|g|i|r): \")\n", - "\n", - "if (language == 'e'): \n", - " print \"Welcome to ProjectEuclid.\"\n", - "elif (language == 'f'):\n", - " print \"Bon jour, ProjectEuclid.\"\n", - "elif (language == 'g'):\n", - " print \"Guten tag, ProjectEuclid.\"\n", - "elif (language == 'i'):\n", - " print \"Bon giorno, ProjectEuclid.\"\n", - "elif (language == 'r'):\n", - " print \"Dobre utre, ProjectEuclid.\"\n", - "else:\n", - " print \"Sorry; we don't speak your language.\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Engl., Fren., Ger., Ital., or Rus.? (e|f|g|i|r): i\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Bon giorno, ProjectEuclid.\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.16, page no. 47" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "score = int(raw_input(\"Enter your test score: \"))\n", - "a = int(score/10)\n", - "if a == 10 or a == 9:\n", - " print \"Your grade is an A.\"\n", - "elif a == 8:\n", - " print \"Your grade is a B.\" \n", - "elif a == 7:\n", - " print \"Your grade is a C.\" \n", - "elif a == 6:\n", - " print \"Your grade is a D.\"\n", - "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", - " print \"Your grade is an F.\" \n", - "else:\n", - " print \"Error: score is out of range.\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter your test score: 83\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Your grade is a B.\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.17, page no. 47" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "score = int(raw_input(\"Enter your test score: \"))\n", - "a = int(score/10)\n", - "if a == 10 or a == 9:\n", - " print \"Your grade is an A.\"\n", - "elif a == 8:\n", - " print \"Your grade is a B.\" \n", - "elif a == 7:\n", - " print \"Your grade is a C.\" \n", - "elif a == 6:\n", - " print \"Your grade is a D.\"\n", - "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", - " print \"Your grade is an F.\" \n", - "else:\n", - " print \"Error: score is out of range.\\n\"\n", - "\n", - "print \"Goodbye.\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter your test score: 83\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Your grade is a B.\n", - "Goodbye.\n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.18, page no. 48" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "score = int(raw_input(\"Enter your test score: \"))\n", - "a = int(score/10)\n", - "if a == 10 or a == 9:\n", - " print \"Your grade is an A.\"\n", - "elif a == 8:\n", - " print \"Your grade is a B.\" \n", - "elif a == 7:\n", - " print \"Your grade is a C.\" \n", - "elif a == 6:\n", - " print \"Your grade is a D.\"\n", - "elif a==5 or a==4 or a==3 or a==2 or a==1 or a==0:\n", - " print \"Your grade is an F.\" \n", - "else:\n", - " print \"Error: score is out of range.\\n\"\n", - "\n", - "print \"Goodbye.\"" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter your test score: 83\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Your grade is a B.\n", - "Goodbye.\n" - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 3.19, page no. 49" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter two integers: \"\n", - "m = int(raw_input())\n", - "n = int(raw_input())\n", - "print min(m,n),\n", - "print 'is the minimum'" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "33 is the minimum\n" - ] - } - ], - "prompt_number": 19 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch4.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch4.ipynb deleted file mode 100755 index 557d2d6a..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch4.ipynb +++ /dev/null @@ -1,1633 +0,0 @@ -{ - "metadata": { - "name": "ch4" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 4: Iteration" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.1, page no. 60" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "i=1\n", - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "s=0\n", - "while (i <= n):\n", - " s += i\n", - " i += 1\n", - "print \"The sum of the first %d integers is %d\" %(i,s)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 6 integers is 15\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.2, page no. 61" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "s=0.0\n", - "i=0\n", - "while (s < bound):\n", - " i += 1\n", - " s += 1.0/i\n", - "\n", - "print \"The sum of the first %d reciprocals is %f\" %(i,s)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 83 reciprocals is 5.002068\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.3, page no. 61" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "print \"Enter a positive number: \"\n", - "x = float(raw_input())\n", - "while (x > 0):\n", - " print \"sqrt(%d) = %f \"%(x,math.sqrt(x))\n", - " print \"Enter another positive number (or 0 to quit): \"\n", - " x = float(raw_input())\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive number: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "sqrt(5) = 2.236068 \n", - "Enter another positive number (or 0 to quit): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "sqrt(3) = 1.732051 \n", - "Enter another positive number (or 0 to quit): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.4, page no. 62" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "i=1\n", - "print \"Enter a positive integer: \";\n", - "n = int(raw_input())\n", - "s=0\n", - "while(True):\n", - " if (i > n):\n", - " break # terminates the loop immediately\n", - " s += i\n", - " i += 1\n", - "print \"The sum of the first %d integers is %d\" %(n,s)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 5 integers is 15\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.5, page no. 62\n" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", - "f0=0\n", - "f1=1\n", - "while (True):\n", - " f2 = f0 + f1\n", - " if (f2 > bound):\n", - " break\n", - " print \", %d\" % f2,\n", - " f0 = f1\n", - " f1 = f2\n", - " " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Fibonacci numbers < 10:\n", - "0, 1 , 1 , 2 , 3 , 5 , 8\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.6, page no. 63" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import sys\n", - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", - "f0=0\n", - "f1=1\n", - "while (True):\n", - " f2 = f0 + f1\n", - " if (f2 > bound):\n", - " sys.exit(0)\n", - " print \", %d\" % f2,\n", - " f0 = f1\n", - " f1 = f2\n", - " " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "ename": "SystemExit", - "evalue": "0", - "output_type": "pyerr", - "traceback": [ - "An exception has occurred, use %tb to see the full traceback.\n", - "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Fibonacci numbers < 10:\n", - "0, 1 , 1 , 2 , 3 , 5 , 8" - ] - }, - { - "output_type": "stream", - "stream": "stderr", - "text": [ - "To exit: use 'exit', 'quit', or Ctrl-D.\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.7, page no. 63" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "print \"Fibonacci numbers < %d:\\n0, 1\" % bound ,\n", - "f0=0\n", - "f1=1\n", - "# Error : infinite loop !\n", - "while (True):\n", - " f2 = f0 + f1\n", - " # By commenting the below if statement, it goes to infinite.\n", - " if (f2 > bound):\n", - " break\n", - " print \", %d\" % f2,\n", - " f0 = f1\n", - " f1 = f2" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n", - "Fibonacci numbers < 10:\n", - "0, 1 , 1 , 2 , 3 , 5 , 8\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.8, page no. 64" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "i=0\n", - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "s=0\n", - "while i<=n:\n", - " s += i\n", - " i += 1\n", - "print \"The sum of the first %d integers is %d\" %(n,s)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 10 integers is 55\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.9, page no. 65" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "print \"Factorial numbers < %d:\\n1, 1\" %bound,\n", - "f=1\n", - "i=1\n", - "while f < bound:\n", - " i += 1\n", - " f *= i\n", - " print \", %d\" %f,\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Factorial numbers < 10:\n", - "1, 1 , 2 , 6 , 24\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.10, page no. 66" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "s=0;\n", - "for i in range(0,n+1):\n", - " s += i\n", - "print \"The sum of the first %d integers is %d\" %(n,s)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 10 integers is 55\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.11, page no. 66" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "s=0\n", - "for i in range(1,n/2): # the scope of this i is this loop\n", - " s += i\n", - "\n", - "for i in range(n/2,n+1): # the scope of this i is this loop\n", - " s += i\n", - "print \"The sum of the first %d integers is %d\" % (n,s)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 10 integers is 55\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.12, page no. 66" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter a positive integer: \"\n", - "bound = int(raw_input())\n", - "\n", - "print \"Factorial numbers that are <= %d:\\n1, 1\" %bound,\n", - "f=1\n", - "for i in range(2,bound+1):\n", - " f *= i\n", - " print \", %d\" % f,\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Factorial numbers that are <= 10:\n", - "1, 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 , 3628800\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.13, page no. 67" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "for i in range(10,0,-1):\n", - " print i,\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "10 9 8 7 6 5 4 3 2 1\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.14, page no. 67" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "prime = True\n", - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "if (n < 2):\n", - " print \"%d is not prime.\" %n\n", - " prime = False\n", - "elif (n < 4):\n", - " print \"%d is prime.\" %n\n", - " prime = False\n", - "elif (n%2 == 0):\n", - " print \"%d = 2* %d\" %(n,n/2)\n", - " prime = False\n", - "else:\n", - " for d in range(3,n/2+1):\n", - " if (n%d == 0):\n", - " print \"%d = %d * %d\" %(n,d,n/d)\n", - " prime = False\n", - "if prime: \n", - " print \"%d is prime.\"%n\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "11\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "11 is prime.\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.15, page no. 68" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter positive integers (0 to quit): \";\n", - "n = int(raw_input())\n", - "m = n\n", - "while n > 0:\n", - " n = int(raw_input())\n", - " if n > m :\n", - " m = n\n", - "\n", - "print \"max = %d\" % m" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter positive integers (0 to quit): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "19\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "42\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "max = 42\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.16, page no. 68" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "print \"Enter positive integers (0 to quit): \";\n", - "n = int(raw_input())\n", - "m = n\n", - "while n > 0: \n", - " if n < m :\n", - " m = n\n", - " n = int(raw_input())\n", - "\n", - "print \"min = %d\" % m\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter positive integers (0 to quit): \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "19\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "42\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "min = 1\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.17, page no. 69" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "m = 95\n", - "n = 11\n", - "while m%n > 0:\n", - " print \"%d modulo %d = %d\" %(m,n,m%n)\n", - " m -= 3\n", - " n += 1\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "95 modulo 11 = 7\n", - "92 modulo 12 = 8\n", - "89 modulo 13 = 11\n", - "86 modulo 14 = 2\n", - "83 modulo 15 = 8\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.18, page no. 69" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "for x in range(1,13):\n", - " for y in range(1,13):\n", - " print \"%4d\" % (x*y),\n", - " print \"\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 1 2 3 4 5 6 7 8 9 10 11 12 \n", - " 2 4 6 8 10 12 14 16 18 20 22 24 \n", - " 3 6 9 12 15 18 21 24 27 30 33 36 \n", - " 4 8 12 16 20 24 28 32 36 40 44 48 \n", - " 5 10 15 20 25 30 35 40 45 50 55 60 \n", - " 6 12 18 24 30 36 42 48 54 60 66 72 \n", - " 7 14 21 28 35 42 49 56 63 70 77 84 \n", - " 8 16 24 32 40 48 56 64 72 80 88 96 \n", - " 9 18 27 36 45 54 63 72 81 90 99 108 \n", - " 10 20 30 40 50 60 70 80 90 100 110 120 \n", - " 11 22 33 44 55 66 77 88 99 110 121 132 \n", - " 12 24 36 48 60 72 84 96 108 120 132 144 \n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.19, page no. 70" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import math\n", - "# defines pow() and log()\n", - "\n", - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "d=0 # the discrete binary logarithm of n\n", - "p2d=1 # = 2^d\n", - "i = n\n", - "while i > 1:\n", - " # INVARIANT: 2^d <= n/i < 2*2^d\n", - " p2d=math.pow(2,d) # = 2^d\n", - " print \"%2d <= %2d\" %(p2d,2*p2d)\n", - " i /= 2\n", - " d += 1\n", - "\n", - "p2d=math.pow(2,d) # = 2^d\n", - "print \"%2d <= %2d < %2d\" %(p2d,n,2*p2d)\n", - "print \" The discrete binary logarithm of is %d\" % d \n", - "lgn = math.log(n)/math.log(2) # base 2 logarithm\n", - "print \"The continuous binary logarithm of is %f\" % lgn" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "17\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 1 <= 2\n", - " 2 <= 4\n", - " 4 <= 8\n", - " 8 <= 16\n", - "16 <= 17 < 32\n", - " The discrete binary logarithm of is 4\n", - "The continuous binary logarithm of is 4.087463\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.20, page no. 71" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "i=1\n", - "print \"Enter a positive integer: \"\n", - "n = int(raw_input())\n", - "s=0\n", - "while (True):\n", - " if (i > n):\n", - " break\n", - " s += i\n", - " i += 1\n", - "\n", - "print \"The sum of the first %d integers is %d\" %(i,s)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter a positive integer: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "10\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The sum of the first 11 integers is 55\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.21, page no. 71" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "count=0\n", - "s=0\n", - "print \"Enter positive integers (0 to quit):\" \n", - "while True: # \"forever\"\n", - " print \"\\t %d :\" %(count + 1),\n", - " n = int(raw_input())\n", - " if (n <= 0):\n", - " break\n", - " count += 1\n", - " s += n\n", - "\n", - "print \"The average of those %d positive numbers is \" %count,\n", - "print float(s)/count\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter positive integers (0 to quit):\n", - "\t 1 :" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "12\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t 2 :" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "32\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t 3 :" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "11\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t 4 :" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " The average of those 3 positive numbers is 18.3333333333\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.22, page no. 72" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "for x in range(1,13):\n", - " for y in range(1,13):\n", - " if y>x:\n", - " break\n", - " else:\n", - " print '%4d' %(x*y),\n", - " print ''\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 1 \n", - " 2 4 \n", - " 3 6 9 \n", - " 4 8 12 16 \n", - " 5 10 15 20 25 \n", - " 6 12 18 24 30 36 \n", - " 7 14 21 28 35 42 49 \n", - " 8 16 24 32 40 48 56 64 \n", - " 9 18 27 36 45 54 63 72 81 \n", - " 10 20 30 40 50 60 70 80 90 100 \n", - " 11 22 33 44 55 66 77 88 99 110 121 \n", - " 12 24 36 48 60 72 84 96 108 120 132 144 \n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.23, page no. 73" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "while True:\n", - " n = int(raw_input('Enter int : '))\n", - " if (n%2 == 0):\n", - " continue\n", - " if (n%3 == 0):\n", - " break\n", - " print \"\\tBottom of loop.\\n\"\n", - "print \"\\tOutside of loop.\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter int : 5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tBottom of loop.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter int : 4\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter int : 6\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter int : 9\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tOutside of loop.\n", - "\n" - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.24, page no. 74" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "N=5\n", - "done=False\n", - "for i in range(N):\n", - " for j in range(N):\n", - " if done:\n", - " break\n", - " for k in range(N):\n", - " if done:\n", - " break\n", - " if (i+j+k>N):\n", - " done = True\n", - " else:\n", - " print i+j+k,\n", - " print \" \",\n", - " print \"* \"\n", - " print \".\" \n", - " done = False\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 1 2 3 4 * \n", - "1 2 3 4 5 * \n", - "2 3 4 5 * \n", - ".\n", - "1 2 3 4 5 * \n", - "2 3 4 5 * \n", - ".\n", - "2 3 4 5 * \n", - ".\n", - "3 4 5 * \n", - ".\n", - "4 5 * \n", - ".\n" - ] - } - ], - "prompt_number": 19 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.25, page no. 75" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "N=5\n", - "done=False\n", - "for i in range(N):\n", - " for j in range(N):\n", - " if done:\n", - " break\n", - " for k in range(N):\n", - " if done:\n", - " break\n", - " if (i+j+k>N):\n", - " done = True\n", - " else:\n", - " print i+j+k,\n", - " print \" \",\n", - " print \"* \"\n", - " print \".\" \n", - " done = False\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 1 2 3 4 * \n", - "1 2 3 4 5 * \n", - "2 3 4 5 * \n", - ".\n", - "1 2 3 4 5 * \n", - "2 3 4 5 * \n", - ".\n", - "2 3 4 5 * \n", - ".\n", - "3 4 5 * \n", - ".\n", - "4 5 * \n", - ".\n" - ] - } - ], - "prompt_number": 20 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.26, page no. 76" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import random\n", - "\n", - "# prints pseudo-random numbers:\n", - "\n", - "for i in range(0,8):\n", - " print random.random()\n", - "\n", - " " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.702115758628\n", - "0.969460447904\n", - "0.409934401112\n", - "0.700339443791\n", - "0.093528851602\n", - "0.132172955687\n", - "0.0162887279366\n", - "0.943010713478\n" - ] - } - ], - "prompt_number": 21 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.27, page no. 77" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import random\n", - "# prints pseudo-random numbers:\n", - "print \"Enter seed: \"\n", - "seed = int(raw_input())\n", - "random.seed(seed);\n", - "for i in range(0,8):\n", - " print random.random()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter seed: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.62290169489\n", - "0.741786989261\n", - "0.795193565566\n", - "0.942450283777\n", - "0.73989857474\n", - "0.922324996665\n", - "0.0290052282836\n", - "0.465622654378\n" - ] - } - ], - "prompt_number": 22 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.28, page no. 78" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import random\n", - "for i in range(0,8):\n", - " print random.random()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.943356716998\n", - "0.648974553137\n", - "0.900900491751\n", - "0.113205964653\n", - "0.469069047782\n", - "0.24657283262\n", - "0.543760859236\n", - "0.573941187928\n" - ] - } - ], - "prompt_number": 23 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 4.29, page no. 79" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import random\n", - "print \"Enter minimum and maximum: \"\n", - "m = int(raw_input())\n", - "n = int(raw_input())\n", - "# lowest and highest numbers\n", - "r = n - m + 1\n", - "# number of numbers in range\n", - "for i in range(0,20):\n", - " j = int(random.random()*100 % r + m)\n", - " print j,\n", - " print \" \",\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter minimum and maximum: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "15\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "6 15 10 8 15 9 7 7 11 6 5 15 14 15 15 15 11 13 14 6 \n" - ] - } - ], - "prompt_number": 24 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch5.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch5.ipynb deleted file mode 100755 index 1fddf23f..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch5.ipynb +++ /dev/null @@ -1,1746 +0,0 @@ -{ - "metadata": { - "name": "" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 5: Functions\n" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.1, Page no:87" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "import math\n", - "\n", - "# tests the sqrt() function:\n", - "for i in range(0,6):\n", - " print \"\\t %d \\t %f\" %(i,math.sqrt(i))" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t 0 \t 0.000000\n", - "\t 1 \t 1.000000\n", - "\t 2 \t 1.414214\n", - "\t 3 \t 1.732051\n", - "\t 4 \t 2.000000\n", - "\t 5 \t 2.236068\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.2, Page no:88" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "import math\n", - "# tests the identity sin 2x = 2 sin x cos x:\n", - "x = 0\n", - "while x < 2:\n", - " print \"%f \\t\\t %f \\t %f\" %(x,math.sin(2*x),2*math.sin(x)*math.cos(x))\n", - " x += 0.2\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.000000 \t\t 0.000000 \t 0.000000\n", - "0.200000 \t\t 0.389418 \t 0.389418\n", - "0.400000 \t\t 0.717356 \t 0.717356\n", - "0.600000 \t\t 0.932039 \t 0.932039\n", - "0.800000 \t\t 0.999574 \t 0.999574\n", - "1.000000 \t\t 0.909297 \t 0.909297\n", - "1.200000 \t\t 0.675463 \t 0.675463\n", - "1.400000 \t\t 0.334988 \t 0.334988\n", - "1.600000 \t\t -0.058374 \t -0.058374\n", - "1.800000 \t\t -0.442520 \t -0.442520\n", - "2.000000 \t\t -0.756802 \t -0.756802\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.3, Page no:90" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def cube(x):\n", - " # returns cube of x:\n", - " return x*x*x\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.4, Page no:91" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def cube(x):\n", - " # returns cube of x:\n", - " return x*x*x\n", - "\n", - "# tests the cube() function:\n", - "n=1\n", - "while (n != 0):\n", - " n = int(raw_input())\n", - " print \"\\tcube( %d ) = %d\" %(n,cube(n))" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tcube( 4 ) = 64\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tcube( 2 ) = 8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tcube( 9 ) = 729\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tcube( 0 ) = 0\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.5, Page no:90" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def maximum(x,y):\n", - " # returns larger of the two given integers:\n", - " if (x < y):\n", - " return y\n", - " else:\n", - " return x\n", - "\n", - "# tests the max() function:\n", - "m = 1\n", - "n = 1\n", - "while m != 0: \n", - " m = int(raw_input())\n", - " n = int(raw_input())\n", - " print \"\\tmax( %d , %d ) = %d\" %(m,n,maximum(m,n))\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax( 5 , 2 ) = 5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax( 0 , 3 ) = 3\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.6, Page no:93" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def maximum(x,y):\n", - " # returns larger of the two given integers:\n", - " if (x < y):\n", - " return y\n", - " else:\n", - " return x\n", - "\n", - "# tests the max() function:\n", - "m = 1\n", - "n = 1\n", - "while m != 0: \n", - " m = int(raw_input())\n", - " n = int(raw_input())\n", - " print \"\\tmax( %d , %d ) = %d\" %(m,n,maximum(m,n))\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax( 5 , 2 ) = 5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax( 0 , 3 ) = 3\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.8, Page no:94" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "\n", - "# returns larger of the two given integers:\n", - "\n", - "m = 1\n", - "n = 1\n", - "while m!=0:\n", - " m = int(raw_input())\n", - " n = int(raw_input())\n", - " print \"\\tmax(%d,%d) = %d\" %(m,n, max(m,n))\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax(5,4) = 5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax(4,3) = 4\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax(8,0) = 8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\tmax(0,5) = 5\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.9, Page no:95" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def fact(n):\n", - " if (n < 0):\n", - " return 0\n", - " f = 1\n", - " while (n > 1):\n", - " f *= n\n", - " n -= 1\n", - " return f\n", - "\n", - "for i in range(-1,6):\n", - " print fact(i),\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 1 1 2 6 24 120\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.10, Page no:95" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def fact(n):\n", - " if (n < 0):\n", - " return 0\n", - " f = 1\n", - " while (n > 1):\n", - " f *= n\n", - " n -= 1\n", - " return f\n", - "\n", - "\n", - "def perm(n,k):\n", - " # returns P(n,k), the number of permutations of k from n:\n", - " if (n < 0 or k < 0 or k > n):\n", - " return 0\n", - " return fact(n)/fact(n-k)\n", - "\n", - "for i in range(-1,8):\n", - " for j in range(-1,i+2):\n", - " print perm(i,j),\n", - " print ''\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 0 \n", - "0 1 0 \n", - "0 1 1 0 \n", - "0 1 2 2 0 \n", - "0 1 3 6 6 0 \n", - "0 1 4 12 24 24 0 \n", - "0 1 5 20 60 120 120 0 \n", - "0 1 6 30 120 360 720 720 0 \n", - "0 1 7 42 210 840 2520 5040 5040 0 \n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.11, Page no:96" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def printDate(m,d,y):\n", - " # prints the given date in literal form:\n", - " if (m < 1 or m > 12 or d < 1 or d > 31 or y < 0):\n", - " print \"Error: parameter out of range.\\n\"\n", - " return\n", - " if m == 1:\n", - " print \"January \",\n", - " elif m ==2:\n", - " print \"February \",\n", - " elif m==3 :\n", - " print \"March \",\n", - " elif m==4:\n", - " print \"April \",\n", - " elif m==5:\n", - " print \"May \",\n", - " elif m==6:\n", - " print \"June \",\n", - " elif m==7:\n", - " print \"July \",\n", - " elif m==8:\n", - " print \"August \",\n", - " elif m==9:\n", - " print \"September \",\n", - " elif m==10:\n", - " print \"October \",\n", - " elif m==1:\n", - " print \"November \",\n", - " else:\n", - " print \"December \",\n", - " print d , \", \", y \n", - "\n", - "# tests the printDate() function:\n", - "month = 1\n", - "while month > 0:\n", - " month = int(raw_input())\n", - " day = int(raw_input())\n", - " year = int(raw_input())\n", - " printDate(month,day,year)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "12\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "1989\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "September 12 , 1989\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2001\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Error: parameter out of range.\n", - "\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.12, Page no:98" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "import string\n", - "def ispunct(s):\n", - " return all(c in string.punctuation for c in s)\n", - "def printCharCategory(c):\n", - " # prints the category to which the given character belongs:\n", - " print \"The character [\" + c + \"] is a \",\n", - " if(c.isdigit()):\n", - " print \"digit.\\n\"\n", - " elif (c.islower()):\n", - " print \"lower-case letter.\\n\"\n", - " elif (c.isupper()): \n", - " print \"capital letter.\\n\"\n", - " elif (c.isspace()):\n", - " print \"white space character.\\n\"\n", - " elif (ord(c) >= 10 and ord(c) <= 15 or ord(c) == 0):\n", - " print \"control character.\\n\"\n", - " elif (ispunct(c)):\n", - " print \"punctuation mark.\\n\"\n", - " else:\n", - " print \"Error.\\n\"\n", - "\n", - "# prints the category to which the given character belongs;\n", - "# tests the printCharCategory() function:\n", - "for c in range(128):\n", - " printCharCategory(chr(c))\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " The character [\u0000] is a control character.\n", - "\n", - "The character [\u0001] is a Error.\n", - "\n", - "The character [\u0002] is a Error.\n", - "\n", - "The character [\u0003] is a Error.\n", - "\n", - "The character [\u0004] is a Error.\n", - "\n", - "The character [\u0005] is a Error.\n", - "\n", - "The character [\u0006] is a Error.\n", - "\n", - "The character [\u0007] is a Error.\n", - "\n", - "The character [\b] is a Error.\n", - "\n", - "The character [\t] is a white space character.\n", - "\n", - "The character [\n", - "] is a white space character.\n", - "\n", - "The character [\u000b", - "] is a white space character.\n", - "\n", - "The character [\f", - "] is a white space character.\n", - "\n", - "The character [\r", - "] is a white space character.\n", - "\n", - "The character [\u000e] is a control character.\n", - "\n", - "The character [\u000f] is a control character.\n", - "\n", - "The character [\u0010] is a Error.\n", - "\n", - "The character [\u0011] is a Error.\n", - "\n", - "The character [\u0012] is a Error.\n", - "\n", - "The character [\u0013] is a Error.\n", - "\n", - "The character [\u0014] is a Error.\n", - "\n", - "The character [\u0015] is a Error.\n", - "\n", - "The character [\u0016] is a Error.\n", - "\n", - "The character [\u0017] is a Error.\n", - "\n", - "The character [\u0018] is a Error.\n", - "\n", - "The character [\u0019] is a Error.\n", - "\n", - "The character [\u001a] is a Error.\n", - "\n", - "The character [\u001b] is a Error.\n", - "\n", - "The character [\u001c", - "] is a Error.\n", - "\n", - "The character [\u001d", - "] is a Error.\n", - "\n", - "The character [\u001e", - "] is a Error.\n", - "\n", - "The character [\u001f] is a Error.\n", - "\n", - "The character [ ] is a white space character.\n", - "\n", - "The character [!] is a punctuation mark.\n", - "\n", - "The character [\"] is a punctuation mark.\n", - "\n", - "The character [#] is a punctuation mark.\n", - "\n", - "The character [$] is a punctuation mark.\n", - "\n", - "The character [%] is a punctuation mark.\n", - "\n", - "The character [&] is a punctuation mark.\n", - "\n", - "The character ['] is a punctuation mark.\n", - "\n", - "The character [(] is a punctuation mark.\n", - "\n", - "The character [)] is a punctuation mark.\n", - "\n", - "The character [*] is a punctuation mark.\n", - "\n", - "The character [+] is a punctuation mark.\n", - "\n", - "The character [,] is a punctuation mark.\n", - "\n", - "The character [-] is a punctuation mark.\n", - "\n", - "The character [.] is a punctuation mark.\n", - "\n", - "The character [/] is a punctuation mark.\n", - "\n", - "The character [0] is a digit.\n", - "\n", - "The character [1] is a digit.\n", - "\n", - "The character [2] is a digit.\n", - "\n", - "The character [3] is a digit.\n", - "\n", - "The character [4] is a digit.\n", - "\n", - "The character [5] is a digit.\n", - "\n", - "The character [6] is a digit.\n", - "\n", - "The character [7] is a digit.\n", - "\n", - "The character [8] is a digit.\n", - "\n", - "The character [9] is a digit.\n", - "\n", - "The character [:] is a punctuation mark.\n", - "\n", - "The character [;] is a punctuation mark.\n", - "\n", - "The character [<] is a punctuation mark.\n", - "\n", - "The character [=] is a punctuation mark.\n", - "\n", - "The character [>] is a punctuation mark.\n", - "\n", - "The character [?] is a punctuation mark.\n", - "\n", - "The character [@] is a punctuation mark.\n", - "\n", - "The character [A] is a capital letter.\n", - "\n", - "The character [B] is a capital letter.\n", - "\n", - "The character [C] is a capital letter.\n", - "\n", - "The character [D] is a capital letter.\n", - "\n", - "The character [E] is a capital letter.\n", - "\n", - "The character [F] is a capital letter.\n", - "\n", - "The character [G] is a capital letter.\n", - "\n", - "The character [H] is a capital letter.\n", - "\n", - "The character [I] is a capital letter.\n", - "\n", - "The character [J] is a capital letter.\n", - "\n", - "The character [K] is a capital letter.\n", - "\n", - "The character [L] is a capital letter.\n", - "\n", - "The character [M] is a capital letter.\n", - "\n", - "The character [N] is a capital letter.\n", - "\n", - "The character [O] is a capital letter.\n", - "\n", - "The character [P] is a capital letter.\n", - "\n", - "The character [Q] is a capital letter.\n", - "\n", - "The character [R] is a capital letter.\n", - "\n", - "The character [S] is a capital letter.\n", - "\n", - "The character [T] is a capital letter.\n", - "\n", - "The character [U] is a capital letter.\n", - "\n", - "The character [V] is a capital letter.\n", - "\n", - "The character [W] is a capital letter.\n", - "\n", - "The character [X] is a capital letter.\n", - "\n", - "The character [Y] is a capital letter.\n", - "\n", - "The character [Z] is a capital letter.\n", - "\n", - "The character [[] is a punctuation mark.\n", - "\n", - "The character [\\] is a punctuation mark.\n", - "\n", - "The character []] is a punctuation mark.\n", - "\n", - "The character [^] is a punctuation mark.\n", - "\n", - "The character [_] is a punctuation mark.\n", - "\n", - "The character [`] is a punctuation mark.\n", - "\n", - "The character [a] is a lower-case letter.\n", - "\n", - "The character [b] is a lower-case letter.\n", - "\n", - "The character [c] is a lower-case letter.\n", - "\n", - "The character [d] is a lower-case letter.\n", - "\n", - "The character [e] is a lower-case letter.\n", - "\n", - "The character [f] is a lower-case letter.\n", - "\n", - "The character [g] is a lower-case letter.\n", - "\n", - "The character [h] is a lower-case letter.\n", - "\n", - "The character [i] is a lower-case letter.\n", - "\n", - "The character [j] is a lower-case letter.\n", - "\n", - "The character [k] is a lower-case letter.\n", - "\n", - "The character [l] is a lower-case letter.\n", - "\n", - "The character [m] is a lower-case letter.\n", - "\n", - "The character [n] is a lower-case letter.\n", - "\n", - "The character [o] is a lower-case letter.\n", - "\n", - "The character [p] is a lower-case letter.\n", - "\n", - "The character [q] is a lower-case letter.\n", - "\n", - "The character [r] is a lower-case letter.\n", - "\n", - "The character [s] is a lower-case letter.\n", - "\n", - "The character [t] is a lower-case letter.\n", - "\n", - "The character [u] is a lower-case letter.\n", - "\n", - "The character [v] is a lower-case letter.\n", - "\n", - "The character [w] is a lower-case letter.\n", - "\n", - "The character [x] is a lower-case letter.\n", - "\n", - "The character [y] is a lower-case letter.\n", - "\n", - "The character [z] is a lower-case letter.\n", - "\n", - "The character [{] is a punctuation mark.\n", - "\n", - "The character [|] is a punctuation mark.\n", - "\n", - "The character [}] is a punctuation mark.\n", - "\n", - "The character [~] is a punctuation mark.\n", - "\n", - "The character [\u007f] is a Error.\n", - "\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.13, Page no:99" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "import math\n", - "def isPrime(n):\n", - " # returns True if n is prime, False otherwise:\n", - " sqrtn = math.sqrt(n)\n", - " if (n < 2):\n", - " return False\n", - " # 0 and 1 are not primes\n", - " if (n < 4):\n", - " return True\n", - " # 2 and 3 are the first primes\n", - " if (n%2 == 0):\n", - " return False\n", - " # 2 is the only even prime\n", - " for d in range(3,int(sqrtn+1),2):\n", - " if (n%d == 0):\n", - " return False\n", - " # n has a nontrivial divisor\n", - " return True;\n", - "\n", - "for n in range(0,80):\n", - " if (isPrime(n)):\n", - " print n,\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.14, Page no:100" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def isLeapYear(y):\n", - " # returns true iff y is a leap year:\n", - " return (y % 4 == 0 and y % 100 != 0 or y % 400 == 0)\n", - "\n", - "# tests the isLeapYear() function:\n", - "n = 2\n", - "while n > 1:\n", - " n = int(raw_input())\n", - " if (isLeapYear(n)):\n", - " print \"%d is a leap year.\" % n\n", - " else:\n", - " print \"%d is not a leap year.\" %n\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2004\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "2004 is a leap year.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2006\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "2006 is not a leap year.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2013\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "2013 is not a leap year.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0 is a leap year.\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.15, Page no: 101" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def age():\n", - " # prompts the user to input his/her age, and returns that value:\n", - " while (True):\n", - " print \"How old are you: \"\n", - " n = int(raw_input())\n", - " if (n < 0):\n", - " print \"\\a\\tYour age could not be negative.\"\n", - " elif (n > 120):\n", - " print \"\\a\\tYou could not be over 120.\"\n", - " else:\n", - " return n\n", - " print \"\\n\\tTry again.\\n\"\n", - "\n", - "a = age();\n", - "print \"\\nYou are %d years old.\" %a\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "How old are you: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "-12\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\u0007\tYour age could not be negative.\n", - "\n", - "\tTry again.\n", - "\n", - "How old are you: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "125\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\u0007\tYou could not be over 120.\n", - "\n", - "\tTry again.\n", - "\n", - "How old are you: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "24\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n", - "You are 24 years old.\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.16, Page no: 102" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def swap(x,y):\n", - " # exchanges the values of x and y:\n", - " x[0],y[0] = y[0],x[0]\n", - "\n", - "a = [22.2]\n", - "b = [44.4]\n", - "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", - "swap(a,b)\n", - "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a = 22.20 , b = 44.40 \n", - "a = 44.40 , b = 22.20 \n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.17, Page no: 104" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python doesn't support pass value by reference. but can be done by passing list.\n", - "'''\n", - "\n", - "def f(x,y):\n", - " x[0]= 88\n", - " y[0] = 99\n", - "\n", - "# tests the f() function:\n", - "a = [22]\n", - "b = [44]\n", - "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", - "f(a,b)\n", - "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n", - "f(2*a,b)\n", - "print \"a = %.2f , b = %.2f \" %(a[0],b[0])\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a = 22.00 , b = 44.00 \n", - "a = 88.00 , b = 99.00 \n", - "a = 88.00 , b = 99.00 \n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.18, Page no: 105" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def computeCircle(r):\n", - " # returns the area and circumference of a circle with radius r:\n", - " PI = 3.141592653589793\n", - " area = PI*r*r\n", - " circumference = 2*PI*r\n", - " return area,circumference\n", - "\n", - "# tests the computeCircle() function:\n", - "print \"Enter radius: \"\n", - "r = int(raw_input())\n", - "a,c = computeCircle(r)\n", - "print \"area = %.2f , circumference = %.2f\" %(a,c)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter radius: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "area = 78.54 , circumference = 31.42\n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.19, Page no: 106" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python passes variable by value and not by reference. So output would be differ.\n", - "'''\n", - "\n", - "\n", - "def f(x,y,z):\n", - " x[0] += z[0]\n", - " y[0] += z[0]\n", - " print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", - "\n", - "x = [22]\n", - "y = [33]\n", - "z = [44]\n", - "\n", - "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", - "f(x,y,z)\n", - "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n", - "x[0] = 2*x[0] - 3\n", - "f(x,y,z)\n", - "print \"x = %d , y = %d , z = %d\" %(x[0],y[0],z[0])\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 22 , y = 33 , z = 44\n", - "x = 66 , y = 77 , z = 44\n", - "x = 66 , y = 77 , z = 44\n", - "x = 173 , y = 121 , z = 44\n", - "x = 173 , y = 121 , z = 44\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.20, Page no: 107" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def cube(x):\n", - " # returns cube of x:\n", - " return x*x*x\n", - "\n", - "# tests the cube() function:\n", - "print cube(4)\n", - "x = int(raw_input())\n", - "y = cube(2*x-3)\n", - "print y\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "64\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "343\n" - ] - } - ], - "prompt_number": 19 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.21, Page no: 108" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Python has it's own scope so output would be differ.\n", - "'''\n", - "x = 11\n", - "\n", - "def f():\n", - " x = 44\n", - " print \"In f(): x = %d\" % x \n", - "\n", - "def g():\n", - " print \"In g(): x = %d\" % x \n", - "\n", - "x = 22\n", - "x = 33\n", - "print \"In block inside main(): x = %d\" % x\n", - "\n", - "\n", - "print \"In main(): x = %d\" % x \n", - "print \"In main(): ::x = %d\" % x \n", - "f()\n", - "g()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In block inside main(): x = 33\n", - "In main(): x = 33\n", - "In main(): ::x = 33\n", - "In f(): x = 44\n", - "In g(): x = 33\n" - ] - } - ], - "prompt_number": 20 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.22, Page no: 109" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def max_(x, y,z=0):\n", - " if x > y and x > y:\n", - " return x\n", - " elif y > x and y > z:\n", - " return y\n", - " else:\n", - " return z\n", - " \n", - " \n", - "print max(99,77), \" \" , max(55,66,33)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "99 66\n" - ] - } - ], - "prompt_number": 21 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.23, Page no: 110" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "# prints the quotient of two input integers:\n", - "print \"Enter two integers: \"\n", - "n = int(raw_input())\n", - "d = int(raw_input())\n", - "if (d == 0):\n", - " import sys\n", - " sys.exit(0)\n", - "print n , \"/\" , d , \" = \" , n/d \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter two integers: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "8 / 2 = 4\n" - ] - } - ], - "prompt_number": 22 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.24, Page no: 110" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def reciprocal(x):\n", - " #returns the reciprocal of x:\n", - " if (x == 0):\n", - " import sys\n", - " sys.exit(1); # terminate the program\n", - " return 1.0/x\n", - "\n", - "x = float(raw_input())\n", - "print reciprocal(x)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "25\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "0.04\n" - ] - } - ], - "prompt_number": 23 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 5.25, Page no: 111" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "This function evaluates the third degree polynomial a0 + a1x + a2x2 + a3x3. \n", - "'''\n", - "def p(x,a0,a1=0,a2=0,a3=0):\n", - " # returns a0 + a1*x + a2*x^2 + a3*x^3:\n", - " return (a0 + (a1 + (a2 + a3*x)*x)*x)\n", - "\n", - "\n", - "# tests the p() function:\n", - "x = 2.0003\n", - "print \"p(x,7) = %f\" % p(x,7)\n", - "print \"p(x,7,6) = %f\" % p(x,7,6)\n", - "print \"p(x,7,6,5) = %f\" % p(x,7,6,5)\n", - "print \"p(x,7,6,5,4) = %f\" % p(x,7,6,5,4)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "p(x,7) = 7.000000\n", - "p(x,7,6) = 19.001800\n", - "p(x,7,6,5) = 39.007800\n", - "p(x,7,6,5,4) = 71.022203\n" - ] - } - ], - "prompt_number": 24 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch6.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch6.ipynb deleted file mode 100755 index 2c52f179..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch6.ipynb +++ /dev/null @@ -1,1276 +0,0 @@ -{ - "metadata": { - "name": "ch6" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 6: Arrays" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.1, page no. 126" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = [0, 0, 0]\n", - "a[2] = 55.55\n", - "a[0] = 11.11\n", - "a[1] = 33.33\n", - "print \"a[0] = \" , a[0] \n", - "print \"a[1] = \" , a[1] \n", - "print \"a[2] = \" , a[2] \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[0] = 11.11\n", - "a[1] = 33.33\n", - "a[2] = 55.55\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.2, page no. 127" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "SIZE=5 # defines the size N for 5 elements\n", - "a = []\n", - "# declares the array's elements as type double\n", - "print \"Enter \" , SIZE , \" numbers:\\t\"\n", - "for i in range(SIZE):\n", - " a.append(float(raw_input()))\n", - " \n", - "print \"In reverse order: \"\n", - "for i in range(SIZE-1,-1,-1):\n", - " print \"\\t\" , a[i]\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter 5 numbers:\t\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "11.11\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33.33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55.55\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77.77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "99.99\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "In reverse order: \n", - "\t99.99\n", - "\t77.77\n", - "\t55.55\n", - "\t33.33\n", - "\t11.11\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.3, page no. 128" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = [ 22.2, 44.4, 66.6 ]\n", - "\n", - "size = len(a)\n", - "for i in range(size):\n", - " print \"\\ta[\" , i , \"] = \" , a[i]\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\ta[ 0 ] = 22.2\n", - "\ta[ 1 ] = 44.4\n", - "\ta[ 2 ] = 66.6\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.4, page no. 128" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = [ 22.2, 44.4, 66.6 , 0 ,0,0,0]\n", - "size = len(a)\n", - "for i in range(size):\n", - " print \"\\ta[\" , i , \"] = \" , a[i] \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\ta[ 0 ] = 22.2\n", - "\ta[ 1 ] = 44.4\n", - "\ta[ 2 ] = 66.6\n", - "\ta[ 3 ] = 0\n", - "\ta[ 4 ] = 0\n", - "\ta[ 5 ] = 0\n", - "\ta[ 6 ] = 0\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.5, page no. 129" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import numpy\n", - "SIZE = 4\n", - "a = numpy.zeros(4)\n", - "# declares the array's elements as type float\n", - "for i in range(SIZE):\n", - " print \"\\ta[\" , i , \"] = \" , a[i]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\ta[ 0 ] = 0.0\n", - "\ta[ 1 ] = 0.0\n", - "\ta[ 2 ] = 0.0\n", - "\ta[ 3 ] = 0.0\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.6, page no. 129" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "SIZE=4\n", - "a = [ 33.3, 44.4, 55.5, 66.6 ]\n", - "for i in range(7): # ERROR: index is out of bounds!\n", - " print \"\\ta[\" , i , \"] = \" , a[i] \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m \u001b[1;36m33.3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m44.4\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m55.5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m66.6\u001b[0m \u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;31m# ERROR: index is out of bounds!\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"\\ta[\"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m,\u001b[0m \u001b[1;34m\"] = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIndexError\u001b[0m: list index out of range" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\ta[ 0 ] = 33.3\n", - "\ta[ 1 ] = 44.4\n", - "\ta[ 2 ] = 55.5\n", - "\ta[ 3 ] = 66.6\n", - "\ta[ 4 ] = " - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.7, page no. 130" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = [ 22.2, 44.4, 66.6 ]\n", - "x=11.1\n", - "print \"x = \" , x \n", - "a.append(88.8) # ERROR: index is out of bounds!\n", - "print \"x = \" , x \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " x = 11.1\n", - "x = 11.1\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.8, page no. 130" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = [ 22.2, 44.4, 66.6 ]\n", - "x=11.1\n", - "print \"x = \" , x \n", - "a[3333] = 88.8 # ERROR: index is out of bounds!\n", - "print \"x = \" , x \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "IndexError", - "evalue": "list assignment index out of range", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m11.1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3333\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m88.8\u001b[0m \u001b[1;31m# ERROR: index is out of bounds!\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"x = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 11.1\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.9, page no. 131" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def sum_(a):\n", - " s = 0\n", - " for i in a:\n", - " s += i\n", - " return s\n", - " \n", - "a = [ 11, 33, 55, 77 ]\n", - "print \"sum(a) = \" , sum_(a) \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "sum(a) = 176\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.10, page no. 132" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def read(a):\n", - " print \"Enter integers. Terminate with 0:\\n\"\n", - " n = 1\n", - " while True:\n", - " n = int(raw_input(\"a[\" + str(len(a)) + \"]: \"))\n", - " if n == 0:\n", - " break\n", - " a.append(n)\n", - " \n", - "\n", - "def print_(a):\n", - " for i in a:\n", - " print i ,\n", - "\n", - "\n", - "a = []\n", - "read(a)\n", - "print \"The array has \" , len(a) , \" elements: \"\n", - "print_(a)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter integers. Terminate with 0:\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[0]: 11\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[1]: 22\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[2]: 33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[3]: 44\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "a[4]: 0\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The array has 4 elements: \n", - "11 22 33 44\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.11, page no. 133" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "import sys\n", - "a = [ 22, 44, 66, 88 ]\n", - "print \"a = \" , id(a) # the address of a[0]\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a = 169156908\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.12, page no. 133" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def index(x,a,n):\n", - " for i in range(len(a)):\n", - " if (a[i] == x):\n", - " return i\n", - " return n # x not found\n", - "\n", - "a = [ 22, 44, 66, 88, 44, 66, 55 ]\n", - "print \"index(44,a,7) = \" , index(44,a,7)\n", - "print \"index(50,a,7) = \" , index(50,a,7) \n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "index(44,a,7) = 1\n", - "index(50,a,7) = 7\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.13, page no. 134" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def sort(a,n):\n", - " # bubble sort:\n", - " n = len(a)\n", - " for i in range(n):\n", - " # bubble up max{a[0..n-i]}:\n", - " for j in range(n-i-1):\n", - " if (a[j] > a[j+1]):\n", - " a[j],a[j+1] = a[j+1],a[j]\n", - "\n", - "def print_(a):\n", - " for i in range(len(a)):\n", - " print a[i],\n", - " print ''\n", - " \n", - "a = [55.5, 22.5, 99.9, 66.6, 44.4, 88.8, 33.3, 77.7]\n", - "\n", - "print_(a)\n", - "sort(a,8)\n", - "print_(a)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "55.5 22.5 99.9 66.6 44.4 88.8 33.3 77.7 \n", - "22.5 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.14, page no. 135" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def index(x,a,n):\n", - " # PRECONDITION: a[0] <= a[1] <= ... <= a[n-1];\n", - " # binary search:\n", - " lo=0\n", - " hi=n-1\n", - " while (lo <= hi):\n", - " i = (lo + hi)/2 # the average of lo and hi\n", - " if (a[i] == x):\n", - " return i\n", - " if (a[i] < x):\n", - " lo = i+1 # continue search in a[i+1..hi]\n", - " else:\n", - " hi = i-1 # continue search in a[lo..i-1]\n", - " return n # x was not found in a[0..n-1]\n", - "\n", - "a = [ 22, 33, 44, 55, 66, 77, 88 ]\n", - "print \"index(44,a,7) = \" , index(44,a,7)\n", - "print \"index(60,a,7) = \" , index(60,a,7) \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "index(44,a,7) = 2\n", - "index(60,a,7) = 7\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.15, page no. 136" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def isNondecreasing(a,n):\n", - " # returns true iff a[0] <= a[1] <= ... <= a[n-1]:\n", - " for i in range(1,n):\n", - " if (a[i]\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m \u001b[1;36m22\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m33\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m55\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m66\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m77\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m88\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m60\u001b[0m \u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 35\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(44,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m7\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 36\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(44,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m44\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 37\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m\"index(60,a,7) = \"\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m60\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36mindex\u001b[1;34m(x, a, n)\u001b[0m\n\u001b[0;32m 18\u001b[0m \u001b[1;31m# PRECONDITION: a[0] <= a[1] <= ... <= a[n-1];\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;31m# binary search:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 20\u001b[1;33m \u001b[1;32massert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0misNondecreasing\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 21\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 22\u001b[0m \u001b[0mlo\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mAssertionError\u001b[0m: " - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "index(44,a,7) = 2\n", - "index(44,a,7) = " - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.17, page no. 137" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "Day = [ 0, 1, 2, 3, 4, 5, 6 ]\n", - "high = [ 88.3, 95.0, 91.2, 89.9, 91.4, 92.5, 86.7]\n", - "\n", - "for i in Day:\n", - " print \"The high temperature for day \" , i , \" was \" , high[i] \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " The high temperature for day 0 was 88.3\n", - "The high temperature for day 1 was 95.0\n", - "The high temperature for day 2 was 91.2\n", - "The high temperature for day 3 was 89.9\n", - "The high temperature for day 4 was 91.4\n", - "The high temperature for day 5 was 92.5\n", - "The high temperature for day 6 was 86.7\n" - ] - } - ], - "prompt_number": 19 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.18, page no. 139" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def sort(a,n):\n", - " a.sort()\n", - "\n", - "def print_(a,n):\n", - " for i in a:\n", - " print i,\n", - " print ''\n", - "a = [55.5, 22.5, 99.9, 66.6, 44.4, 88.8, 33.3, 77.7]\n", - "print_(a,8);\n", - "sort(a,8)\n", - "print_(a,8)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "55.5 22.5 99.9 66.6 44.4 88.8 33.3 77.7 \n", - "22.5 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n" - ] - } - ], - "prompt_number": 20 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.19, page no. 139" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def read(a):\n", - " print \"Enter 15 integers, 5 per row:\\n\"\n", - " for i in range(3):\n", - " ar = []\n", - " print \"Row \" , i , \": \",\n", - " for j in range(5):\n", - " ar.append(int(raw_input()))\n", - " a.append(ar)\n", - "\n", - "def print_(a):\n", - " for i in range(3):\n", - " for j in range(5):\n", - " print a[i][j],\n", - " print ''\n", - "a = []\n", - "read(a)\n", - "print_(a)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter 15 integers, 5 per row:\n", - "\n", - "Row 0 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "11\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " Row 1 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "60\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "50\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "30\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "90\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "70\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " Row 2 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "85\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "25\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "45\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "45\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "55\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 44 77 33 11 44 \n", - "60 50 30 90 70 \n", - "85 25 45 45 55 \n" - ] - } - ], - "prompt_number": 21 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.20, page no. 140" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def read(score):\n", - " for s in range(3):\n", - " print \"Student \" , s , \": \",\n", - " st = []\n", - " for q in range(5):\n", - " st.append(int(raw_input()))\n", - " score.append(st)\n", - "\n", - "def printQuizAverages(score):\n", - " for s in range(3):\n", - " sm = 0\n", - " for q in range(5):\n", - " sm += score[s][q]\n", - " print \"\\tStudent \" , s , \": \" , sm/5.0\n", - "\n", - "def printClassAverages(score):\n", - " for q in range(5):\n", - " sm = 0\n", - " for s in range(3):\n", - " sm += score[s][q]\n", - " print \"\\tQuiz \" , q , \": \" , sm/3.0\n", - "\n", - "\n", - "\n", - "NUM_STUDENTS = 3\n", - "NUM_QUIZZES = 5\n", - "\n", - "\n", - "score = []\n", - "print \"Enter \" , NUM_QUIZZES , \" scores for each student: \"\n", - "read(score)\n", - "print \"The quiz averages are:\"\n", - "printQuizAverages(score)\n", - "print \"The class averages are: \"\n", - "printClassAverages(score)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter 5 scores for each student: \n", - "Student 0 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "7\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " Student 1 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " Student 2 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "5\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "6\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "7\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "8\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " The quiz averages are:\n", - "\tStudent 0 : 8.2\n", - "\tStudent 1 : 8.8\n", - "\tStudent 2 : 7.0\n", - "The class averages are: \n", - "\tQuiz 0 : 7.33333333333\n", - "\tQuiz 1 : 7.33333333333\n", - "\tQuiz 2 : 8.33333333333\n", - "\tQuiz 3 : 8.33333333333\n", - "\tQuiz 4 : 8.66666666667\n" - ] - } - ], - "prompt_number": 24 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 6.21, page no. 141" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def numZeros(a,n1,n2,n3):\n", - " count = 0\n", - " for i in range(n1):\n", - " for j in range(n2):\n", - " for k in range(n3):\n", - " if (a[i][j][k] == 0):\n", - " count += 1\n", - " return count\n", - "\n", - "\n", - "a = [ [ [5,0,2], [0,0,9], [4,1,0], [7,7,7] ],[ [3,0,0], [8,5,0], [0,0,0], [2,0,9] ]]\n", - "print \"This array has \" , numZeros(a,2,4,3) , \" zeros\"\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "This array has 11 zeros\n" - ] - } - ], - "prompt_number": 25 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch7.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch7.ipynb deleted file mode 100755 index 63248e07..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch7.ipynb +++ /dev/null @@ -1,750 +0,0 @@ -{ - "metadata": { - "name": "ch7" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Capter 7: Pointers and References" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.1, Page no: 157" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "n=44\n", - "print \"n = \" , n \n", - "# prints the value of n\n", - "print \"&n = \" , hex(id(n)) # prints the address of n\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 44\n", - "&n = 0x8fc0eec\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.2, Page no: 157" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : Python doesn't support reference/pointer variable. But can be achieved by using mutable datatypes i.e. list.\n", - "'''\n", - "\n", - "\n", - "n = [44]\n", - "rn=n # r is a synonym for n\n", - "print \"n = \" , n , \", rn = \" , rn \n", - "n[0] -= 1\n", - "print \"n = \" , n , \", rn = \" , rn \n", - "rn[0] *= 2\n", - "print \"n = \" , n , \", rn = \" , rn \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = [44] , rn = [44]\n", - "n = [43] , rn = [43]\n", - "n = [86] , rn = [86]\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.3, Page no: 158" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "n = [44]\n", - "rn=n # r is a synonym for n\n", - "print \"&n = \" , hex(id(n)) , \", rn = \" , hex(id(rn ))\n", - "rn2 = n\n", - "rn3 = rn\n", - "print \"&rn2 = \" , hex(id(rn2)) , \", rn = \" , hex(id(rn ))\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "&n = 0x9c6228c , rn = 0x9c6228c\n", - "&rn2 = 0x9c6228c , rn = 0x9c6228c\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.4, Page no: 159" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "n = [44]\n", - "print \"n = \" , n , \", &n = \" , hex(id(n))\n", - "pn = n\n", - "print \"pn = \" , hex(id(pn)) , \", &pn = \" , hex(id(hex(id(pn))))\n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = [44] , &n = 0x9c624ec\n", - "pn = 0x9c624ec , &pn = 0x9c6aa60\n" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.5, Page no: 159" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "n = [44]\n", - "print \"n = \" , n , \", &n = \" , hex(id(n))\n", - "pn = n\n", - "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", - "print \"*pn = \" , pn\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = [44] , &n = 0x9c58d6c\n", - "\tpn = 0x9c58d6c ,\n", - " &pn = 0x9c6ab20\n", - "*pn = [44]\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.6, Page no: 160" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "n = [44]\n", - "print \"n = \" , n , \", &n = \" , hex(id(n))\n", - "pn = n\n", - "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", - "print \"*pn = \" , pn\n", - "ppn = pn\n", - "\n", - "print \" ppn = \" , hex(id(hex(id(ppn)))) \n", - "print \" &ppn = \" , hex(id(hex(id(hex(id(ppn))))))\n", - "print \" *ppn = \" , hex(id(ppn)) \n", - "print \"**ppn = \" , ppn \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = [44] , &n = 0x9bf05ac\n", - "\tpn = 0x9bf05ac ,\n", - " &pn = 0x9c58160\n", - "*pn = [44]\n", - " ppn = 0x9c58680\n", - " &ppn = 0x9c58160\n", - " *ppn = 0x9bf05ac\n", - "**ppn = [44]\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.7, Page no: 160" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "n = [44]\n", - "print \"n = \" , n , \"\\n &n = \" , hex(id(n))\n", - "pn = n\n", - "print \"\\tpn = \" , hex(id(pn)) , \",\\n &pn = \" , hex(id(hex(id(pn))))\n", - "print \"*pn = \" , pn\n", - "nn = pn\n", - "print \" ppn = \" , hex(id(nn))\n", - "print \" &ppn = \" , hex(id(hex(id(nn))))\n", - "rpn = pn\n", - "print \" ppn = \" , hex(id(rpn))\n", - "print \" &ppn = \" , hex(id(hex(id(rpn))))\n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = [44] \n", - " &n = 0x9bf60ec\n", - "\tpn = 0x9bf60ec ,\n", - " &pn = 0x9bf0e40\n", - "*pn = [44]\n", - " ppn = 0x9bf60ec\n", - " &ppn = 0x9bf0e40\n", - " ppn = 0x9bf60ec\n", - " &ppn = 0x9bf0f20\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.8, Page no: 162" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def max_(m,n):\n", - " if m>n:\n", - " return m\n", - " else:\n", - " return n\n", - "\n", - "m = 44\n", - "n = 22\n", - "print m , \", \" , n , \", \" , max_(m,n)\n", - "m = max_(m,n) \n", - "m = 55\n", - "# changes the value of m from 44 to 55\n", - "print m , \", \" , n , \", \" , max_(m,n) \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "44 , 22 , 44\n", - "55 , 22 , 55\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.9, Page no: 163" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "v = []\n", - "for k in range(1,5):\n", - " v.append(1.0/k)\n", - "\n", - "for i in range(4):\n", - " print \"v[\" , i , \"] = \" , v[i]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "v[ 0 ] = 1.0\n", - "v[ 1 ] = 0.5\n", - "v[ 2 ] = 0.333333333333\n", - "v[ 3 ] = 0.25\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.10, Page no: 163" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "import sys\n", - "a = [22, 33, 44]\n", - "\n", - "print \"a = \" , hex(id(a))\n", - "print \"sizeof(int) = \" , sys.getsizeof(1) \n", - "s = 0\n", - "for i in a:\n", - " s += i\n", - " print \"\\t i = \" , hex(id(i)),\n", - " print \"\\t *i = \" , i,\n", - " print \"\\t sum = \" , s\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a = 0x9bf688c\n", - "sizeof(int) = 12\n", - "\t i = 0x8fc0ff4 \t *i = 22 \t sum = 22\n", - "\t i = 0x8fc0f70 \t *i = 33 \t sum = 55\n", - "\t i = 0x8fc0eec \t *i = 44 \t sum = 99\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.11, Page no: 165" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "a = [22, 33, 44, 55, 66]\n", - "print \"a = \" , hex(id(a)) , \", *a = \" , a[0] \n", - "for p in a:\n", - " print \"p = \" , hex(id(p)) , \", *p = \" , p \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "a = 0x9c6526c , *a = 22\n", - "p = 0x8fc0ff4 , *p = 22\n", - "p = 0x8fc0f70 , *p = 33\n", - "p = 0x8fc0eec , *p = 44\n", - "p = 0x8fc0e68 , *p = 55\n", - "p = 0x8fc0de4 , *p = 66\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.12, Page no: 165" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def loc(a1,a2,n1,n2):\n", - " p = []\n", - " for element in a2:\n", - " if element in a1:\n", - " p.append(element)\n", - " return p\n", - "\n", - "a1 = [11, 11, 11, 11, 11, 22, 33, 44, 55]\n", - "a2 = [11, 11, 11, 22, 33]\n", - "print \"Array a1 begins at location\\t\" , hex(id(a1 ))\n", - "print \"Array a2 begins at location\\t\" , hex(id(a2)) \n", - "p = loc(a1, a2, 9, 5)\n", - "if (p):\n", - " print \"Array a2 found at location\\t\" , hex(id(p))\n", - " for i in range(len(p)):\n", - " print \"\\t\" , hex(id(p[i])) , \": \" , p[i], \"\\t\" , hex(id(a2[i])) , \": \" , a2[i] \n", - "else:\n", - " print \"Not found.\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Array a1 begins at location\t0x9bea56c\n", - "Array a2 begins at location\t0x9bea62c\n", - "Array a2 found at location\t0x9bea6cc\n", - "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", - "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", - "\t0x8fc1078 : 11 \t0x8fc1078 : 11\n", - "\t0x8fc0ff4 : 22 \t0x8fc0ff4 : 22\n", - "\t0x8fc0f70 : 33 \t0x8fc0f70 : 33\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.13, Page no: 166" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def get(a):\n", - " print \"Enter number of items: \"\n", - " n = int(raw_input())\n", - " print \"Enter \" , n , \" items, one per line:\"\n", - " for i in range(n):\n", - " print \"\\t\" , i+1 , \": \",\n", - " a.append(float(raw_input()))\n", - "\n", - "def print_(a):\n", - " for i in range(len(a)):\n", - " print a[i] ,\n", - " print ''\n", - "\n", - "a = []\n", - "get(a)\n", - "print_(a)\n", - "a = []\n", - "get(a)\n", - "print_(a)\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter number of items: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "4\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter 4 items, one per line:\n", - "\t1 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44.4\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t2 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "77.7\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t3 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "22.2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t4 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "88.8\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 44.4 77.7 22.2 88.8 \n", - "Enter number of items: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "2\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter 2 items, one per line:\n", - "\t1 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "3.33\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " \t2 : " - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "9.99\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - " 3.33 9.99 \n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.14, Page no: 167" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def sort(p, n):\n", - " for i in range(1,n):\n", - " for j in range(n-i):\n", - " if (p[j] > p[j+1]):\n", - " p[j],p[j+1] = p[j+1],p[j]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 7.15, Page no: 168" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def sum_(k,n):\n", - " # returns the sum f(0) + f(1) + f(2) + . . . + f(n-1):\n", - " s = 0\n", - " for i in range(1,n+1):\n", - " s += k(i)\n", - " return s\n", - "\n", - "def square(k):\n", - " return k*k\n", - "\n", - "def cube(k):\n", - " return k*k*k\n", - "\n", - "\n", - "print sum_(square,4) # 1 + 4 + 9 + 16\n", - "print sum_(cube,4) # 1 + 8 + 27 + 64\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "30\n", - "100\n" - ] - } - ], - "prompt_number": 15 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch8.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch8.ipynb deleted file mode 100755 index 2b83cace..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch8.ipynb +++ /dev/null @@ -1,1064 +0,0 @@ -{ - "metadata": { - "name": "ch8" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 8: C- Strings" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.1, page no. 184" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "n= [44] # n holds the int 44\n", - "print \"int n=44; // n holds the int 44:\\n\";\n", - "print \"\\t\\t n = \" , n \n", - "print \"\\t\\t &n = \" , hex(id(n))\n", - "pn = n \n", - "print \"int* pn=&n; // pn holds the address of n:\\n\";\n", - "print \"\\t\\t n = \" , n \n", - "print \"\\t\\t &n = \" , hex(id(n))\n", - "print \"\\t\\t pn = \" , hex(id(pn)) \n", - "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", - "print \"\\t\\t *pn = \" , pn\n", - "\n", - "pn[0] = 77 # changes the value of n to 77\n", - "print \"*pn = 77; // changes the value of n to 77:\\n\";\n", - "print \"\\t\\t n = \" , n \n", - "print \"\\t\\t &n = \" , hex(id(n))\n", - "print \"\\t\\t pn = \" , hex(id(pn)) \n", - "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", - "print \"\\t\\t *pn = \" , pn\n", - "\n", - "q = n \n", - "print \"int* q=&n; // q also holds the address of n:\\n\";\n", - "print \"\\t\\t n = \" , n \n", - "print \"\\t\\t &n = \" , hex(id(n))\n", - "print \"\\t\\t pn = \" , hex(id(pn)) \n", - "print \"\\t\\t &pn = \" , hex(id(hex(id(pn))))\n", - "print \"\\t\\t *pn = \" , pn\n", - "print \"\\t\\t q = \" , hex(id(q))\n", - "print \"\\t\\t &q = \" , hex(id(hex(id(hex(id(pn))))))\n", - "print \"\\t\\t *q = \" , q \n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "int n=44; // n holds the int 44:\n", - "\n", - "\t\t n = [44]\n", - "\t\t &n = 0x9bfb92c\n", - "int* pn=&n; // pn holds the address of n:\n", - "\n", - "\t\t n = [44]\n", - "\t\t &n = 0x9bfb92c\n", - "\t\t pn = 0x9bfb92c\n", - "\t\t &pn = 0x9bf5aa0\n", - "\t\t *pn = [44]\n", - "*pn = 77; // changes the value of n to 77:\n", - "\n", - "\t\t n = [77]\n", - "\t\t &n = 0x9bfb92c\n", - "\t\t pn = 0x9bfb92c\n", - "\t\t &pn = 0x9c6a760\n", - "\t\t *pn = [77]\n", - "int* q=&n; // q also holds the address of n:\n", - "\n", - "\t\t n = [77]\n", - "\t\t &n = 0x9bfb92c\n", - "\t\t pn = 0x9bfb92c\n", - "\t\t &pn = 0x9bf5c80\n", - "\t\t *pn = [77]\n", - "\t\t q = 0x9bfb92c\n", - "\t\t &q = 0x9c6a760\n", - "\t\t *q = [77]\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.2, page no. 185" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s = \"ABCD\"\n", - "for i in range(4):\n", - " print \"s[\" , i , \"] = '\" , s[i] , \"'\\n\";\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "s[ 0 ] = ' A '\n", - "\n", - "s[ 1 ] = ' B '\n", - "\n", - "s[ 2 ] = ' C '\n", - "\n", - "s[ 3 ] = ' D '\n", - "\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.3, page no. 186" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "while True:\n", - " word = raw_input()\n", - " if len(word) < 2:\n", - " break\n", - " l = word.split(' ')\n", - " for i in l:\n", - " print '\\t\"' , i , '\"'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Today's date is March 12, 2000.\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t\" Today's \"\n", - "\t\" date \"\n", - "\t\" is \"\n", - "\t\" March \"\n", - "\t\" 12, \"\n", - "\t\" 2000. \"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Tomorrow is Monday.\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t\" Tomorrow \"\n", - "\t\" is \"\n", - "\t\" Monday. \"\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.4, page no. 187" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "while True:\n", - " line = raw_input()\n", - " if len(line) < 2:\n", - " break\n", - " print \"\\t[\" , line , \"]\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Once upon a midnight dreary, while I pondered, weak and weary,\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t[ Once upon a midnight dreary, while I pondered, weak and weary, ]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Over a many quaint and curious volume of forgotten lore,\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t[ Over a many quaint and curious volume of forgotten lore, ]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.5, page no. 187" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "while True:\n", - " word = raw_input()\n", - " if len(word) < 2:\n", - " break\n", - " l = word.split(',')\n", - " for i in range(len(l)-1):\n", - " print '\\t[' , l[i] , ']'\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Once upon a midnight dreary, while I pondered, weak and weary,\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t[ Once upon a midnight dreary ]\n", - "\t[ while I pondered ]\n", - "\t[ weak and weary ]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Over a many quaint and curious volume of forgotten lore,\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t[ Over a many quaint and curious volume of forgotten lore ]\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.6, page no. 188" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "count = 0\n", - "while True:\n", - " a = raw_input()\n", - " if len(a) < 1:\n", - " break\n", - " for ch in a:\n", - " if (ch == 'e'): count+=1\n", - " \n", - "print count , \" e's were counted.\\n\"\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Once upon a midnight dreary, while I pondered, weak and weary,\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Over many a quaint and curious volume of forgotten lore,\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "11 e's were counted.\n", - "\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.7, page no. 188" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "while True:\n", - " a = raw_input()\n", - " if len(a) < 1:\n", - " break\n", - " print a.title()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Fourscore and seven years ago our fathers\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Fourscore And Seven Years Ago Our Fathers\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "brought forth upon this continent a new nation,\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Brought Forth Upon This Continent A New Nation,\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.8, page no. 189" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "a = raw_input()\n", - "l = a.split(' ')\n", - "nos = []\n", - "for i in l:\n", - " try:\n", - " i = int(i)\n", - " nos.append(i)\n", - " except:\n", - " continue\n", - "m = nos[0]\n", - "n = nos[1] \n", - "print m , \" + \" , n , \" = \" , m+n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "what is 305 plus 9416 ?\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "305 + 9416 = 9721\n" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.10, page no. 191" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "count=0\n", - "\n", - "print \"Enter at most 4 names with at most 19 characters:\\n\";\n", - "while (True):\n", - " n = raw_input()\n", - " if len(n) < 1:\n", - " break\n", - " name.append(n)\n", - " count += 1\n", - " \n", - "print \"The names are:\\n\"\n", - "for i in range(count):\n", - " print \"\\t\" , i , \". [\" , name[i] , \"]\" \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter at most 4 names with at most 19 characters:\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "George Washington\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "John Adams\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Thomas Jefferson\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The names are:\n", - "\n", - "\t0 . [ George Washington ]\n", - "\t1 . [ John Adams ]\n", - "\t2 . [ Thomas Jefferson ]\n" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.11, page no. 192" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "name = []\n", - "count=0\n", - "\n", - "print \"Enter at most 4 names with at most 19 characters:\\n\";\n", - "while (True):\n", - " n = raw_input()\n", - " if len(n) < 1:\n", - " break\n", - " name.append(n)\n", - " count += 1\n", - " \n", - "print \"The names are:\\n\"\n", - "for i in range(count):\n", - " print \"\\t\" , i , \". [\" , name[i] , \"]\" " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Enter at most 4 names with at most 19 characters:\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "George Washington\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "John Adams\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Thomas Jefferson\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The names are:\n", - "\n", - "\t0 . [ George Washington ]\n", - "\t1 . [ John Adams ]\n", - "\t2 . [ Thomas Jefferson ]\n" - ] - } - ], - "prompt_number": 13 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.12, page no. 193" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "name = [ \"George Washington\", \"John Adams\", \"Thomas Jefferson\"]\n", - "print \"The names are:\\n\"\n", - "for i in range(3):\n", - " print \"\\t\" , i , \". [\" , name[i] , \"]\"\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The names are:\n", - "\n", - "\t0 . [ George Washington ]\n", - "\t1 . [ John Adams ]\n", - "\t2 . [ Thomas Jefferson ]\n" - ] - } - ], - "prompt_number": 14 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.13, page no. 193" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s = \"ABCDEFG\"\n", - "print \"len(\" , s , \") = \" , len(s) \n", - "print \"len(\\\"\\\") = \" , len(\"\")\n", - "print \"Enter string: \"\n", - "b = raw_input()\n", - "print \"len(\" , b , \") = \" , len(b)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "len( ABCDEFG ) = 7\n", - "len(\"\") = 0\n", - "Enter string: \n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "hello how are you !!!\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "len( hello how are you !!! ) = 21\n" - ] - } - ], - "prompt_number": 15 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.14, page no. 194" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s = \"The Mississippi is a long river.\"\n", - "print 's = \"' , s , '\"'\n", - "p = s.find(' ')\n", - "print \"find(s, ' ') points to s[\" , p , \"].\"\n", - "p = s.find('s')\n", - "print \"find(s, 's') points to s[\" , p , \"].\"\n", - "p = s.rfind('s')\n", - "print \"reverse find(s, 's') points to s[\" , p , \"].\"\n", - "p = s.find(\"is\")\n", - "print \"strstr(s, \\\"is\\\") points to s[\" , p , \"].\"\n", - "p = s.find(\"isi\")\n", - "if p== -1:\n", - " print 's.find(\"isi\") returns NULL'\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "s = \" The Mississippi is a long river. \"\n", - "find(s, ' ') points to s[ 3 ].\n", - "find(s, 's') points to s[ 6 ].\n", - "reverse find(s, 's') points to s[ 17 ].\n", - "strstr(s, \"is\") points to s[ 5 ].\n", - "s.find(\"isi\") returns NULL\n" - ] - } - ], - "prompt_number": 16 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.15, page no. 195" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s1 = \"ABCDEFG\"\n", - "s2 = \"XYZ\" \n", - "print \"Before strcpy(s1,s2):\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", - "s1 = s2\n", - "print \"After strcpy(s1,s2):\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Before strcpy(s1,s2):\n", - "\n", - "\ts1 = [ ABCDEFG ], length = 7\n", - "\ts2 = [ XYZ ], length = 3\n", - "After strcpy(s1,s2):\n", - "\n", - "\ts1 = [ XYZ ], length = 3\n", - "\ts2 = [ XYZ ], length = 3\n" - ] - } - ], - "prompt_number": 17 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.16, page no. 195" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s1 = \"ABCDEFG\"\n", - "s2 = \"XYZ\" \n", - "print \"Before strcpy(s1,s2,2):\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", - "s1 = s2[:2] + s1[2:]\n", - "print \"After strcpy(s1,s2,2):\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", - "\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Before strcpy(s1,s2,2):\n", - "\n", - "\ts1 = [ ABCDEFG ], length = 7\n", - "\ts2 = [ XYZ ], length = 3\n", - "After strcpy(s1,s2,2):\n", - "\n", - "\ts1 = [ XYCDEFG ], length = 7\n", - "\ts2 = [ XYZ ], length = 3\n" - ] - } - ], - "prompt_number": 18 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.17, page no. 196" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s1 = \"ABCDEFG\"\n", - "s2 = \"XYZ\" \n", - "print \"Before string concatination :\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", - "s1 += s2\n", - "print \"After string concatination :\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Before string concatination :\n", - "\n", - "\ts1 = [ ABCDEFG ], length = 7\n", - "\ts2 = [ XYZ ], length = 3\n", - "After string concatination :\n", - "\ts1 = [ ABCDEFGXYZ ], length = 10\n", - "\ts2 = [ XYZ ], length = 3\n" - ] - } - ], - "prompt_number": 19 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.18, page no. 197" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s1 = \"ABCDEFG\"\n", - "s2 = \"XYZ\" \n", - "print \"Before string concatination :\\n\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) \n", - "s1 += s2[:2]\n", - "print \"After string concatination :\" \n", - "print \"\\ts1 = [\" , s1 , \"], length = \" , len(s1) \n", - "print \"\\ts2 = [\" , s2 , \"], length = \" , len(s2) " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "Before string concatination :\n", - "\n", - "\ts1 = [ ABCDEFG ], length = 7\n", - "\ts2 = [ XYZ ], length = 3\n", - "After string concatination :\n", - "\ts1 = [ ABCDEFGXY ], length = 9\n", - "\ts2 = [ XYZ ], length = 3\n" - ] - } - ], - "prompt_number": 20 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.19, page no. 197" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "s = \"Today's date is March 12, 2000.\"\n", - "\n", - "print \"The string is: [\" , s , \"] \\nIts tokens are: \"\n", - "p = s.split(\" \")\n", - "\n", - "for i in p:\n", - " print \"\\t[\" , i , \"] \"\n", - "\n", - "print \"Now the string is: [\" , p[0] , \"] \";\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "The string is: [ Today's date is March 12, 2000. ] \n", - "Its tokens are: \n", - "\t[ Today's ] \n", - "\t[ date ] \n", - "\t[ is ] \n", - "\t[ March ] \n", - "\t[ 12, ] \n", - "\t[ 2000. ] \n", - "Now the string is: [ Today's ] \n" - ] - } - ], - "prompt_number": 21 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 8.20, page no. 199" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def strpbrk(s,s1):\n", - " found = []\n", - " for i in range(len(s1)):\n", - " if s1[i] in s:\n", - " index = s.find(s1[i])\n", - " found.append(index)\n", - " if found:\n", - " return min(found)\n", - " return None\n", - " \n", - "\n", - "s = \"The Mississippi is a long river.\"\n", - "print 's = \"' , s , '\"'\n", - "p = strpbrk(s, \"nopqr\")\n", - "print 'strpbrk(s, \"nopqr\") points to s[' , p , \"].\"\n", - "p = strpbrk(s, \"NOPQR\")\n", - "if (p == None):\n", - " print 'strpbrk(s, \"NOPQR\") returns NULL.\\n'" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "s = \" The Mississippi is a long river. \"\n", - "strpbrk(s, \"nopqr\") points to s[ 12 ].\n", - "strpbrk(s, \"NOPQR\") returns NULL.\n", - "\n" - ] - } - ], - "prompt_number": 22 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/ch9.ipynb b/Schaum's_Outlines:_Programming_with_C++/ch9.ipynb deleted file mode 100755 index d8416ec9..00000000 --- a/Schaum's_Outlines:_Programming_with_C++/ch9.ipynb +++ /dev/null @@ -1,444 +0,0 @@ -{ - "metadata": { - "name": "ch9" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": [ - "Chapter 9: Standard C++ strings" - ] - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.2, Page no: 214" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "while True:\n", - " try:\n", - " n = int(raw_input())\n", - " print \"n = \" , n \n", - " except:\n", - " break" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "46\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 46\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "22\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 22\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "44\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 44\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "66\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 66\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "88\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "n = 88\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "33,\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.4, Page no: 215" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "king = [] # defines king to be an array \n", - "n=0\n", - "while True:\n", - " name = raw_input()\n", - " if len(name) < 1:\n", - " break\n", - " king.append(name)\n", - " n += 1\n", - "# now n == the number of names read\n", - "for i in range(n):\n", - " print '\\t' , i+1 , \". \" , king[i] " - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Kenneth II (971-995)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Constantine III (995-997)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Kenneth III (997-1005)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Malcolm II (1005-1034)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Duncan I (1034-1040)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Macbeth (1040-1057)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Lulach (1057-1058)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Malcolm III (1058-1093)\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "\t1 . Kenneth II (971-995)\n", - "\t2 . Constantine III (995-997)\n", - "\t3 . Kenneth III (997-1005)\n", - "\t4 . Malcolm II (1005-1034)\n", - "\t5 . Duncan I (1034-1040)\n", - "\t6 . Macbeth (1040-1057)\n", - "\t7 . Lulach (1057-1058)\n", - "\t8 . Malcolm III (1058-1093)\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.6, Page no: 217" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''\n", - "Note : you need input.txt in same directory for the program to run without any errors.\n", - "'''\n", - "\n", - "infile = open(\"input.txt\",\"r\")\n", - "outfile = open(\"output.txt\",\"w\")\n", - "\n", - "for i in infile:\n", - " s = i.title()\n", - " outfile.write(s)\n", - "\n", - "infile.close()\n", - "outfile.close()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'input.txt'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[0;32m 6\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0minfile\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"input.txt\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0moutfile\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"output.txt\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"w\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'input.txt'" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.7, Page no: 218" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "'''Note: You need the files - north.dat, south.dat, combined.dat in the same directory for the program to run without any errors'''\n", - "\n", - "fin1 = open(\"north.dat\",\"r\")\n", - "fin2 = open(\"south.dat\",\"r\")\n", - "fout = open(\"combined.dat\",\"w\")\n", - "\n", - "file1 = []\n", - "file2 = []\n", - "for i in fin1:\n", - " try:\n", - " s = i.split(\" \")\n", - " for j in s:\n", - " file1.append(int(j))\n", - " except:\n", - " continue\n", - " \n", - "for i in fin2:\n", - " try:\n", - " s = i.split(\" \")\n", - " for j in s:\n", - " file2.append(int(j))\n", - " except:\n", - " continue\n", - "\n", - "\n", - "for i in sorted(file1 + file2):\n", - " fout.write(str(i) + \" \")\n", - "\n", - "fin1.close()\n", - "fin2.close()\n", - "fout.close()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "ename": "IOError", - "evalue": "[Errno 2] No such file or directory: 'north.dat'", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mIOError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m '''\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mfin1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"north.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[0mfin2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"south.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"r\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mfout\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"combined.dat\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"w\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIOError\u001b[0m: [Errno 2] No such file or directory: 'north.dat'" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.8, Page no: 219" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def print_(oss):\n", - " print 'oss.str() = \"' , str(oss) , '\"'\n", - "\n", - "s=\"ABCDEFG\"\n", - "n=33\n", - "x=2.718\n", - "l = ''\n", - "print_(l)\n", - "l += s\n", - "print_(l)\n", - "l += ( \" \" + str(n) )\n", - "print_(l)\n", - "l += ( \" \" + str(x) )\n", - "print_(l)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "oss.str() = \" \"\n", - "oss.str() = \" ABCDEFG \"\n", - "oss.str() = \" ABCDEFG 33 \"\n", - "oss.str() = \" ABCDEFG 33 2.718 \"\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 2, - "metadata": {}, - "source": [ - "Example 9.9, Page no: 220" - ] - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "def print_(iss,s='',n=0,x=0.0):\n", - " print 's = \"' , s , '\", n = ' , n , \", x = \" , x, ', iss.str() = \"' \\\n", - " , iss , '\"' \n", - "\n", - "s=\"\"\n", - "n=0\n", - "x=0.0\n", - "l = ''\n", - "iss = \"ABCDEFG 44 3.14\"\n", - "print_(iss)\n", - "s = \"ABCDEFG\"\n", - "print_(iss,s)\n", - "n = 44\n", - "print_(iss,s,n)\n", - "x = 3.14\n", - "print_(iss,s,n,x)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "s = \" \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", - "s = \" ABCDEFG \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", - "s = \" ABCDEFG \", n = 44 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", - "s = \" ABCDEFG \", n = 44 , x = 3.14 , iss.str() = \" ABCDEFG 44 3.14 \"\n" - ] - } - ], - "prompt_number": 6 - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/Schaum's_Outlines:_Programming_with_C++/screenshots/ratio.png b/Schaum's_Outlines:_Programming_with_C++/screenshots/ratio.png deleted file mode 100755 index 68bb8cd0..00000000 Binary files a/Schaum's_Outlines:_Programming_with_C++/screenshots/ratio.png and /dev/null differ diff --git a/Schaum's_Outlines:_Programming_with_C++/screenshots/swap.png b/Schaum's_Outlines:_Programming_with_C++/screenshots/swap.png deleted file mode 100755 index 7d707e37..00000000 Binary files a/Schaum's_Outlines:_Programming_with_C++/screenshots/swap.png and /dev/null differ diff --git a/Schaum's_Outlines:_Programming_with_C++/screenshots/vector.png b/Schaum's_Outlines:_Programming_with_C++/screenshots/vector.png deleted file mode 100755 index b51554ce..00000000 Binary files a/Schaum's_Outlines:_Programming_with_C++/screenshots/vector.png and /dev/null differ -- cgit