summaryrefslogtreecommitdiff
path: root/C++_Demystified:_A_Self-Teaching_Guide
diff options
context:
space:
mode:
authorkinitrupti2015-10-15 17:40:30 +0530
committerkinitrupti2015-10-15 17:40:30 +0530
commit4a735f833653551e3321fbe9a8e47faa879d282f (patch)
treedb91b182e06d1695ad8db15d757f669ad929c0b6 /C++_Demystified:_A_Self-Teaching_Guide
parent78784b374b2d1a9be66eb4ad41470409e2bd4dfa (diff)
downloadPython-Textbook-Companions-4a735f833653551e3321fbe9a8e47faa879d282f.tar.gz
Python-Textbook-Companions-4a735f833653551e3321fbe9a8e47faa879d282f.tar.bz2
Python-Textbook-Companions-4a735f833653551e3321fbe9a8e47faa879d282f.zip
solved errors
Diffstat (limited to 'C++_Demystified:_A_Self-Teaching_Guide')
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter13-checkpoint.ipynb412
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter5-checkpoint.ipynb488
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/.ipynb_checkpoints/chapter9-checkpoint.ipynb1033
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/chapter13.ipynb13
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/chapter5.ipynb27
-rwxr-xr-xC++_Demystified:_A_Self-Teaching_Guide/chapter9.ipynb65
-rw-r--r--C++_Demystified:_A_Self-Teaching_Guide/students.dat0
7 files changed, 1995 insertions, 43 deletions
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 = <open file 'students.dat', mode 'w' at 0x2d80a50>\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<ipython-input-1-112e202a5944>\u001b[0m in \u001b[0;36m<module>\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/<ipython-input-1-44ee42c69511>\u001b[0m in \u001b[0;36m<module>\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<lambda>\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<ipython-input-8-42e131eb489c>\u001b[0m in \u001b[0;36m<module>\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<ipython-input-8-42e131eb489c>\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
--- /dev/null
+++ b/C++_Demystified:_A_Self-Teaching_Guide/students.dat