summaryrefslogtreecommitdiff
path: root/_Programming_With_C
diff options
context:
space:
mode:
authorHardik Ghaghada2014-06-20 15:52:25 +0530
committerHardik Ghaghada2014-06-20 15:52:25 +0530
commite1e59ca3a50d9f93e8b7bc0693b8081d5db77771 (patch)
treef54eab21dd3d725d64a495fcd47c00d37abed004 /_Programming_With_C
parenta78126bbe4443e9526a64df9d8245c4af8843044 (diff)
parent83c1bfceb1b681b4bb7253b47491be2d8b2014a1 (diff)
downloadPython-Textbook-Companions-e1e59ca3a50d9f93e8b7bc0693b8081d5db77771.tar.gz
Python-Textbook-Companions-e1e59ca3a50d9f93e8b7bc0693b8081d5db77771.tar.bz2
Python-Textbook-Companions-e1e59ca3a50d9f93e8b7bc0693b8081d5db77771.zip
Merge pull request #1 from debashisdeb/master
removing problem statements from all the chapters to avoid copyright violations
Diffstat (limited to '_Programming_With_C')
-rw-r--r--_Programming_With_C/chapter1.ipynb121
-rw-r--r--_Programming_With_C/chapter10.ipynb366
-rw-r--r--_Programming_With_C/chapter11.ipynb745
-rw-r--r--_Programming_With_C/chapter12.ipynb3
-rw-r--r--_Programming_With_C/chapter13.ipynb3
-rw-r--r--_Programming_With_C/chapter14.ipynb3
-rw-r--r--_Programming_With_C/chapter2.ipynb2
-rw-r--r--_Programming_With_C/chapter3.ipynb3
-rw-r--r--_Programming_With_C/chapter4.ipynb17
-rw-r--r--_Programming_With_C/chapter5.ipynb2
-rw-r--r--_Programming_With_C/chapter6.ipynb23
-rw-r--r--_Programming_With_C/chapter7.ipynb13
-rw-r--r--_Programming_With_C/chapter8.ipynb9
-rw-r--r--_Programming_With_C/chapter9.ipynb8
14 files changed, 1085 insertions, 233 deletions
diff --git a/_Programming_With_C/chapter1.ipynb b/_Programming_With_C/chapter1.ipynb
index 599cad41..c1eb1997 100644
--- a/_Programming_With_C/chapter1.ipynb
+++ b/_Programming_With_C/chapter1.ipynb
@@ -1,61 +1,62 @@
-{
- "metadata": {
- "name": ""
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h1>Chapter 1: Introductory Concepts <h1>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Example 1.6, Page number: 1.19<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "# Area of a Circle\n",
- "\n",
- "import math\n",
- "\n",
- "radius=5\n",
- "area=math.pi*radius*radius\n",
- "print \"Area = \",area\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Area = 78.5398163397\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:be853ba23904264307d7e754c6f226daff90dc0e3bd2eca38f5b65419e2b80bc"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 1: Introductory Concepts <h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 1.6, Page number: 1.19<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "import math\n",
+ "\n",
+ "radius=5\n",
+ "area=math.pi*radius*radius\n",
+ "print \"Area = \",area\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Area = 78.5398163397\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
} \ No newline at end of file
diff --git a/_Programming_With_C/chapter10.ipynb b/_Programming_With_C/chapter10.ipynb
index 083baffa..ea2e1985 100644
--- a/_Programming_With_C/chapter10.ipynb
+++ b/_Programming_With_C/chapter10.ipynb
@@ -1,6 +1,7 @@
{
"metadata": {
- "name": "chapter10"
+ "name": "",
+ "signature": "sha256:3323f7a9a077b84fffdd30478d4b0d0b7f4032b86670a58b5b333d42bee04f15"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -10,24 +11,33 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h1>Chapter 10: Strings<h1> "
+ "source": [
+ "<h1>Chapter 10: Strings<h1> "
+ ]
},
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.3, Page Number: 10.3<h3>"
+ "source": [
+ "<h3>Example 10.3, Page Number: 10.3<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "st='Programming'\nprint 'The string is %s' %st",
+ "input": [
+ "st='Programming'\n",
+ "print 'The string is %s' %st"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The string is Programming\n"
+ "text": [
+ "The string is Programming\n"
+ ]
}
],
"prompt_number": 4
@@ -35,19 +45,28 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.4, Page Number: 10.4<h3>"
+ "source": [
+ "<h3>Example 10.4, Page Number: 10.4<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "st='Hello World'\nprint 'The line is :'\nprint st",
+ "input": [
+ "st='Hello World'\n",
+ "print 'The line is :'\n",
+ "print st"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The line is :\nHello World\n"
+ "text": [
+ "The line is :\n",
+ "Hello World\n"
+ ]
}
],
"prompt_number": 5
@@ -55,19 +74,29 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.6, Page Number: 10.5<h3>"
+ "source": [
+ "<h3>Example 10.6, Page Number: 10.5<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "#display the string character by character\n\nstrin='Welcome to python'\nfor i in strin:\n print i,",
+ "input": [
+ "\n",
+ "\n",
+ "strin='Welcome to python'\n",
+ "for i in strin:\n",
+ " print i,"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "W e l c o m e t o p y t h o n\n"
+ "text": [
+ "W e l c o m e t o p y t h o n\n"
+ ]
}
],
"prompt_number": 6
@@ -75,19 +104,48 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.7, Page Number: 10.6<h3>"
+ "source": [
+ "<h3>Example 10.7, Page Number: 10.6<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# to demonstrate the use of operators related function\n\nstr1='Programming'\nlen1=len(str1)\nprint 'The length of the string is ',len1\n\nstr2=str1\nprint 'First string is %s and copied string is %s' %(str1,str2)\n\nstr3='Computer'\n\nif str1==str3:\n print 'Both strings are equal'\nelif str1<str2:\n print 'First string is lesser than second string'\nelse:\n print 'First string is greater than second string'\n \ntempstr=' with C'\nstr1=str1+tempstr\nprint 'The concated string is ',str1\n",
+ "input": [
+ "\n",
+ "\n",
+ "str1='Programming'\n",
+ "len1=len(str1)\n",
+ "print 'The length of the string is ',len1\n",
+ "\n",
+ "str2=str1\n",
+ "print 'First string is %s and copied string is %s' %(str1,str2)\n",
+ "\n",
+ "str3='Computer'\n",
+ "\n",
+ "if str1==str3:\n",
+ " print 'Both strings are equal'\n",
+ "elif str1<str2:\n",
+ " print 'First string is lesser than second string'\n",
+ "else:\n",
+ " print 'First string is greater than second string'\n",
+ " \n",
+ "tempstr=' with C'\n",
+ "str1=str1+tempstr\n",
+ "print 'The concated string is ',str1\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The length of the string is 11\nFirst string is Programming and copied string is Programming\nFirst string is greater than second string\nThe concated string is Programming with C\n"
+ "text": [
+ "The length of the string is 11\n",
+ "First string is Programming and copied string is Programming\n",
+ "First string is greater than second string\n",
+ "The concated string is Programming with C\n"
+ ]
}
],
"prompt_number": 7
@@ -95,19 +153,48 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.8,Page Number: 10.7<h3>"
+ "source": [
+ "<h3>Example 10.8,Page Number: 10.7<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# user defined function for string length and string copy\n\ndef strlength(str1):\n count=0\n for i in str1:\n count+=1\n \n return count\ndef strcopy(src):\n dst=[]\n for i in src:\n dst.append(i)\n \n dst=''.join(dst)\n \n return dst\n\n\nstr1='New Delhi'\nlen1=strlength(str1)\nprint 'The length of the string is ',len1\n\nstr2=strcopy(str1)\nprint 'First string is %s and copied string is %s' %(str1,str2)\n",
+ "input": [
+ "\n",
+ "def strlength(str1):\n",
+ " count=0\n",
+ " for i in str1:\n",
+ " count+=1\n",
+ " \n",
+ " return count\n",
+ "def strcopy(src):\n",
+ " dst=[]\n",
+ " for i in src:\n",
+ " dst.append(i)\n",
+ " \n",
+ " dst=''.join(dst)\n",
+ " \n",
+ " return dst\n",
+ "\n",
+ "\n",
+ "str1='New Delhi'\n",
+ "len1=strlength(str1)\n",
+ "print 'The length of the string is ',len1\n",
+ "\n",
+ "str2=strcopy(str1)\n",
+ "print 'First string is %s and copied string is %s' %(str1,str2)\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The length of the string is 9\nFirst string is New Delhi and copied string is New Delhi\n"
+ "text": [
+ "The length of the string is 9\n",
+ "First string is New Delhi and copied string is New Delhi\n"
+ ]
}
],
"prompt_number": 8
@@ -115,19 +202,53 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.9,Page Number: 10.9<h3>"
+ "source": [
+ "<h3>Example 10.9,Page Number: 10.9<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# A user defined implementation of comparison of two strings\n\ndef strcompare(str1,str2):\n \n len1=len(str1)\n len2=len(str2)\n \n if len1<len2:\n length=len1\n else:\n length=len2\n \n for i in xrange(0,length):\n if str1[i]<str2[i]:\n return -1\n elif str1[i]>str2[i]:\n return 1\n \n return 0\n\nstr1='Programming'\nstr2='Computer'\nstatus=strcompare(str1,str2)\nif status==-1:\n print 'First string is lesser than second string'\nelif status==1:\n print 'First string is greater than second string'\nelse:\n print 'Both strings ae equal'\n",
+ "input": [
+ "\n",
+ "\n",
+ "def strcompare(str1,str2):\n",
+ " \n",
+ " len1=len(str1)\n",
+ " len2=len(str2)\n",
+ " \n",
+ " if len1<len2:\n",
+ " length=len1\n",
+ " else:\n",
+ " length=len2\n",
+ " \n",
+ " for i in xrange(0,length):\n",
+ " if str1[i]<str2[i]:\n",
+ " return -1\n",
+ " elif str1[i]>str2[i]:\n",
+ " return 1\n",
+ " \n",
+ " return 0\n",
+ "\n",
+ "str1='Programming'\n",
+ "str2='Computer'\n",
+ "status=strcompare(str1,str2)\n",
+ "if status==-1:\n",
+ " print 'First string is lesser than second string'\n",
+ "elif status==1:\n",
+ " print 'First string is greater than second string'\n",
+ "else:\n",
+ " print 'Both strings ae equal'\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "First string is greater than second string\n"
+ "text": [
+ "First string is greater than second string\n"
+ ]
}
],
"prompt_number": 9
@@ -135,19 +256,42 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.10, Page Number: 10.10<h3>"
+ "source": [
+ "<h3>Example 10.10, Page Number: 10.10<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Left as well as right concatenation of two strings\n\ndef leftconcat(dst,src):\n dst=src+dst\n return dst\n\ndef rightconcat(dst,src):\n dst=dst+src\n return dst\n\nstr1='Hello'\nstr2='Friends'\n\ntempstr=leftconcat(str2,str1)\nprint 'The first string after left concatenation becomes ', tempstr\n\ntempstr=rightconcat(str2,str1)\nprint 'The first string after right concatenation becomes', tempstr\n",
+ "input": [
+ "\n",
+ "def leftconcat(dst,src):\n",
+ " dst=src+dst\n",
+ " return dst\n",
+ "\n",
+ "def rightconcat(dst,src):\n",
+ " dst=dst+src\n",
+ " return dst\n",
+ "\n",
+ "str1='Hello'\n",
+ "str2='Friends'\n",
+ "\n",
+ "tempstr=leftconcat(str2,str1)\n",
+ "print 'The first string after left concatenation becomes ', tempstr\n",
+ "\n",
+ "tempstr=rightconcat(str2,str1)\n",
+ "print 'The first string after right concatenation becomes', tempstr\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The first string after left concatenation becomes HelloFriends\nThe first string after right concatenation becomes FriendsHello\n"
+ "text": [
+ "The first string after left concatenation becomes HelloFriends\n",
+ "The first string after right concatenation becomes FriendsHello\n"
+ ]
}
],
"prompt_number": 10
@@ -155,19 +299,34 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.11,Page Numbr: 10.12<h3>"
+ "source": [
+ "<h3>Example 10.11,Page Numbr: 10.12<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# program to count total number of vowel in a given text\n\nstr1='All good boys have bread'\ncount=0\n\nfor i in str1:\n if i=='a' or i=='e'or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U' :\n count+=1\n \nprint 'Total number of vowels in a given text are ',count",
+ "input": [
+ "\n",
+ "\n",
+ "str1='All good boys have bread'\n",
+ "count=0\n",
+ "\n",
+ "for i in str1:\n",
+ " if i=='a' or i=='e'or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U' :\n",
+ " count+=1\n",
+ " \n",
+ "print 'Total number of vowels in a given text are ',count"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Total number of vowels in a given text are 8\n"
+ "text": [
+ "Total number of vowels in a given text are 8\n"
+ ]
}
],
"prompt_number": 11
@@ -175,19 +334,44 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.12, Page Number: 10.13<h3>"
+ "source": [
+ "<h3>Example 10.12, Page Number: 10.13<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Character arithmetic examples\n\nch1='A'\nch2=ord(ch1)+3\nprint chr(ch2)\n\nch1=chr(ord(ch1)+1)\nprint ch1\n\nprint ord('a')\nprint ord('l')\n\nval=ord(ch1)*ch2\nprint val\n\nprint chr(100)",
+ "input": [
+ "\n",
+ "ch1='A'\n",
+ "ch2=ord(ch1)+3\n",
+ "print chr(ch2)\n",
+ "\n",
+ "ch1=chr(ord(ch1)+1)\n",
+ "print ch1\n",
+ "\n",
+ "print ord('a')\n",
+ "print ord('l')\n",
+ "\n",
+ "val=ord(ch1)*ch2\n",
+ "print val\n",
+ "\n",
+ "print chr(100)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "D\nB\n97\n108\n4488\nd\n"
+ "text": [
+ "D\n",
+ "B\n",
+ "97\n",
+ "108\n",
+ "4488\n",
+ "d\n"
+ ]
}
],
"prompt_number": 12
@@ -195,19 +379,39 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.13, Page Number: 10.13<h3>"
+ "source": [
+ "<h3>Example 10.13, Page Number: 10.13<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Program to convert lowercase alphabets to uppercase in a given text\n\ntext='I am studying 6 Theory Papers & 4 practicals'\n\nlen1=len(text)\ntext=list(text)\nfor i in xrange(0,len1):\n if text[i]>='a' and text[i]<='z':\n text[i]=chr(ord(text[i])+ord('A')-ord('a'))\n \n \ntext=''.join(text)\n\nprint 'The text after converting lowercase alphabets to uppercase is '\nprint text",
+ "input": [
+ "\n",
+ "text='I am studying 6 Theory Papers & 4 practicals'\n",
+ "\n",
+ "len1=len(text)\n",
+ "text=list(text)\n",
+ "for i in xrange(0,len1):\n",
+ " if text[i]>='a' and text[i]<='z':\n",
+ " text[i]=chr(ord(text[i])+ord('A')-ord('a'))\n",
+ " \n",
+ " \n",
+ "text=''.join(text)\n",
+ "\n",
+ "print 'The text after converting lowercase alphabets to uppercase is '\n",
+ "print text"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The text after converting lowercase alphabets to uppercase is \nI AM STUDYING 6 THEORY PAPERS & 4 PRACTICALS\n"
+ "text": [
+ "The text after converting lowercase alphabets to uppercase is \n",
+ "I AM STUDYING 6 THEORY PAPERS & 4 PRACTICALS\n"
+ ]
}
],
"prompt_number": 13
@@ -215,19 +419,45 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.14, Page Number: 10.14<h3>"
+ "source": [
+ "<h3>Example 10.14, Page Number: 10.14<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Program to search for a substring in a given string\n\ntext='The programming is a systematic process'\nsubstr='pro'\ntext_len=len(text)\nsub_len=len(substr)\ntext=list(text)\nsubstr=list(substr)\n\nfor i in xrange(0,text_len-sub_len+1):\n \n for j in xrange(0,sub_len):\n \n if text[i+j]==substr[j]:\n continue\n else:\n break\n \n if j==sub_len-1:\n print 'The substring is present from subscript %d onwards' %i\n \n",
+ "input": [
+ "\n",
+ "text='The programming is a systematic process'\n",
+ "substr='pro'\n",
+ "text_len=len(text)\n",
+ "sub_len=len(substr)\n",
+ "text=list(text)\n",
+ "substr=list(substr)\n",
+ "\n",
+ "for i in xrange(0,text_len-sub_len+1):\n",
+ " \n",
+ " for j in xrange(0,sub_len):\n",
+ " \n",
+ " if text[i+j]==substr[j]:\n",
+ " continue\n",
+ " else:\n",
+ " break\n",
+ " \n",
+ " if j==sub_len-1:\n",
+ " print 'The substring is present from subscript %d onwards' %i\n",
+ " \n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The substring is present from subscript 4 onwards\nThe substring is present from subscript 32 onwards\n"
+ "text": [
+ "The substring is present from subscript 4 onwards\n",
+ "The substring is present from subscript 32 onwards\n"
+ ]
}
],
"prompt_number": 14
@@ -235,19 +465,77 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 10.15,Page number: 10.15<h3>"
+ "source": [
+ "<h3>Example 10.15,Page number: 10.15<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Reordering a list of strings\n\n\ndef reorder(x):\n\n n=len(x)\n for item in range(0,n-1):\n for i in range(item+1,n):\n if x[item]>x[i]:\n temp=x[item]\n x[item]=x[i]\n x[i]=temp\n\n\n return\n\nx=['PACIFIC','ATLANTIC','INDIAN','CARIBBEAN','BERING','BLACK','RED','NORTH','BALTIC','CASPIAN']\nprint 'Original list of strings :\\n\\n'\n\nfor i in x:\n print \"String : \",i\n\nreorder(x)\n\nprint \"\\nReodered list of strings : \\n\\n\"\n\nfor i in x:\n print \"String : \",i\n",
+ "input": [
+ "\n",
+ "\n",
+ "def reorder(x):\n",
+ "\n",
+ " n=len(x)\n",
+ " for item in range(0,n-1):\n",
+ " for i in range(item+1,n):\n",
+ " if x[item]>x[i]:\n",
+ " temp=x[item]\n",
+ " x[item]=x[i]\n",
+ " x[i]=temp\n",
+ "\n",
+ "\n",
+ " return\n",
+ "\n",
+ "x=['PACIFIC','ATLANTIC','INDIAN','CARIBBEAN','BERING','BLACK','RED','NORTH','BALTIC','CASPIAN']\n",
+ "print 'Original list of strings :\\n\\n'\n",
+ "\n",
+ "for i in x:\n",
+ " print \"String : \",i\n",
+ "\n",
+ "reorder(x)\n",
+ "\n",
+ "print \"\\nReodered list of strings : \\n\\n\"\n",
+ "\n",
+ "for i in x:\n",
+ " print \"String : \",i\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Original list of strings :\n\n\nString : PACIFIC\nString : ATLANTIC\nString : INDIAN\nString : CARIBBEAN\nString : BERING\nString : BLACK\nString : RED\nString : NORTH\nString : BALTIC\nString : CASPIAN\n\nReodered list of strings : \n\n\nString : ATLANTIC\nString : BALTIC\nString : BERING\nString : BLACK\nString : CARIBBEAN\nString : CASPIAN\nString : INDIAN\nString : NORTH\nString : PACIFIC\nString : RED\n"
+ "text": [
+ "Original list of strings :\n",
+ "\n",
+ "\n",
+ "String : PACIFIC\n",
+ "String : ATLANTIC\n",
+ "String : INDIAN\n",
+ "String : CARIBBEAN\n",
+ "String : BERING\n",
+ "String : BLACK\n",
+ "String : RED\n",
+ "String : NORTH\n",
+ "String : BALTIC\n",
+ "String : CASPIAN\n",
+ "\n",
+ "Reodered list of strings : \n",
+ "\n",
+ "\n",
+ "String : ATLANTIC\n",
+ "String : BALTIC\n",
+ "String : BERING\n",
+ "String : BLACK\n",
+ "String : CARIBBEAN\n",
+ "String : CASPIAN\n",
+ "String : INDIAN\n",
+ "String : NORTH\n",
+ "String : PACIFIC\n",
+ "String : RED\n"
+ ]
}
],
"prompt_number": 15
@@ -255,7 +543,7 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "",
+ "input": [],
"language": "python",
"metadata": {},
"outputs": [],
diff --git a/_Programming_With_C/chapter11.ipynb b/_Programming_With_C/chapter11.ipynb
index 1f4127e4..d858cd07 100644
--- a/_Programming_With_C/chapter11.ipynb
+++ b/_Programming_With_C/chapter11.ipynb
@@ -1,6 +1,7 @@
{
"metadata": {
- "name": "chapter11"
+ "name": "",
+ "signature": "sha256:81f953770b0acac35782d6d61b5968cf0c7681b2e047ca75cfe8abd7244d5bab"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -10,24 +11,49 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h1>Chapter 11: Pointers<h1>"
+ "source": [
+ "<h1>Chapter 11: Pointers<h1>"
+ ]
},
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.1, Page 11.2<h3>"
+ "source": [
+ "<h3>Example 11.1, Page 11.2<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# realtionship between two variables, their address and associated pointers\n\n\nu,v=[3],[]\npu=u\nv=pu\npv=v\n\nprint \"u=\",u[0],\nprint \"&u=\",id(u),\nprint \"pu=\",id(u),\nprint \"*pu\",pu[0]\n\nprint \"v=\",v[0],\nprint \"&v=\",id(v),\nprint \"pv=\",id(v),\nprint \"*pv\",pv[0]\n",
+ "input": [
+ "\n",
+ "\n",
+ "\n",
+ "u,v=[3],[]\n",
+ "pu=u\n",
+ "v=pu\n",
+ "pv=v\n",
+ "\n",
+ "print \"u=\",u[0],\n",
+ "print \"&u=\",id(u),\n",
+ "print \"pu=\",id(u),\n",
+ "print \"*pu\",pu[0]\n",
+ "\n",
+ "print \"v=\",v[0],\n",
+ "print \"&v=\",id(v),\n",
+ "print \"pv=\",id(v),\n",
+ "print \"*pv\",pv[0]\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "u= 3 &u= 56575840 pu= 56575840 *pu 3\nv= 3 &v= 56575840 pv= 56575840 *pv 3\n"
+ "text": [
+ "u= 3 &u= 56575840 pu= 56575840 *pu 3\n",
+ "v= 3 &v= 56575840 pv= 56575840 *pv 3\n"
+ ]
}
],
"prompt_number": 11
@@ -35,19 +61,32 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.2, Page number: 11.3<h3>"
+ "source": [
+ "<h3>Example 11.2, Page number: 11.3<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# a simple program using pointers\n\n\nv=[3]\nu1=2*(v[0]+5)\npv=v\nu2=2*(pv[0]+5)\n\nprint \"u1=%d u2=%d\" %(u1,u2)",
+ "input": [
+ "\n",
+ "\n",
+ "v=[3]\n",
+ "u1=2*(v[0]+5)\n",
+ "pv=v\n",
+ "u2=2*(pv[0]+5)\n",
+ "\n",
+ "print \"u1=%d u2=%d\" %(u1,u2)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "u1=16 u2=16\n"
+ "text": [
+ "u1=16 u2=16\n"
+ ]
}
],
"prompt_number": 12
@@ -55,19 +94,32 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.3, Page munber: 11.4<h3>"
+ "source": [
+ "<h3>Example 11.3, Page munber: 11.4<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# a simple programme using pointers\n\nv=[3]\npv=v\nprint \"*pv=%d v=%d\" %(pv[0],v[0])\n\npv[0]=0\nprint \"*pv=%d v=%d\" %(pv[0],v[0])",
+ "input": [
+ "\n",
+ "v=[3]\n",
+ "pv=v\n",
+ "print \"*pv=%d v=%d\" %(pv[0],v[0])\n",
+ "\n",
+ "pv[0]=0\n",
+ "print \"*pv=%d v=%d\" %(pv[0],v[0])"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "*pv=3 v=3\n*pv=0 v=0\n"
+ "text": [
+ "*pv=3 v=3\n",
+ "*pv=0 v=0\n"
+ ]
}
],
"prompt_number": 13
@@ -75,19 +127,53 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.7, Page number: 11.6<h3>"
+ "source": [
+ "<h3>Example 11.7, Page number: 11.6<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# difference between by pass by reference and pass by value\n\n\ndef funct1(u,v):\n u=0\n v=0\n print \"Within funct1 : u=%d v=%d\" %(u,v)\n return\n\ndef funct2(u,v):\n u[0]=0\n v[0]=0\n print \"Within funct2 : *pu=%d *pv=%d\" %(u[0],v[0])\n return\n\nu=[1]\nv=[3]\n\nprint \"Before calling funct1: u=%d v=%d\" %(u[0],v[0])\nfunct1(u[0],v[0])\nprint \"After calling funct1 : u=%d v=%d\" %(u[0],v[0])\n\nprint \"Before calling funct2: u=%d v=%d\" %(u[0],v[0])\nfunct2(u,v)\nprint \"After calling funct2 : u=%d v=%d\" %(u[0],v[0])",
+ "input": [
+ "\n",
+ "\n",
+ "def funct1(u,v):\n",
+ " u=0\n",
+ " v=0\n",
+ " print \"Within funct1 : u=%d v=%d\" %(u,v)\n",
+ " return\n",
+ "\n",
+ "def funct2(u,v):\n",
+ " u[0]=0\n",
+ " v[0]=0\n",
+ " print \"Within funct2 : *pu=%d *pv=%d\" %(u[0],v[0])\n",
+ " return\n",
+ "\n",
+ "u=[1]\n",
+ "v=[3]\n",
+ "\n",
+ "print \"Before calling funct1: u=%d v=%d\" %(u[0],v[0])\n",
+ "funct1(u[0],v[0])\n",
+ "print \"After calling funct1 : u=%d v=%d\" %(u[0],v[0])\n",
+ "\n",
+ "print \"Before calling funct2: u=%d v=%d\" %(u[0],v[0])\n",
+ "funct2(u,v)\n",
+ "print \"After calling funct2 : u=%d v=%d\" %(u[0],v[0])"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Before calling funct1: u=1 v=3\nWithin funct1 : u=0 v=0\nAfter calling funct1 : u=1 v=3\nBefore calling funct2: u=1 v=3\nWithin funct2 : *pu=0 *pv=0\nAfter calling funct2 : u=0 v=0\n"
+ "text": [
+ "Before calling funct1: u=1 v=3\n",
+ "Within funct1 : u=0 v=0\n",
+ "After calling funct1 : u=1 v=3\n",
+ "Before calling funct2: u=1 v=3\n",
+ "Within funct2 : *pu=0 *pv=0\n",
+ "After calling funct2 : u=0 v=0\n"
+ ]
}
],
"prompt_number": 14
@@ -95,19 +181,62 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.8, Page number: 11.8<h3>"
+ "source": [
+ "<h3>Example 11.8, Page number: 11.8<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Analyzing a line of text\n\n\n\ndef scan_line(line,pv,pc,pd,pw,po):\n\n for c in line:\n\n if c=='A' or c=='E' or c=='I' or c=='O' or c=='U':\n pv[0]+=1\n elif c>='A' and c<='Z':\n pc[0]+=1\n elif c>='0' and c<='9':\n pd[0]+=1\n elif c==' ' or c=='\\t':\n pw[0]+=1\n else:\n po[0]+=1\n\n return\n\n\nvowel,consonants,digits,whitespc,other=[0],[0],[0],[0],[0]\nline=\"Personal computers with memories in excess of 4096 KB are now quite common.\"\nline=line.upper()\nscan_line(line,vowel,consonants,digits,whitespc,other)\nprint \"\\n\\n\"\nprint \"No. of vowels : \",vowel[0]\nprint \"No. of consonants : \",consonants[0]\nprint \"No. of digits : \",digits[0]\nprint \"No. of whitespace characters : \",whitespc[0]\nprint \"No. of other characters : \",other[0]",
+ "input": [
+ "\n",
+ "\n",
+ "\n",
+ "def scan_line(line,pv,pc,pd,pw,po):\n",
+ "\n",
+ " for c in line:\n",
+ "\n",
+ " if c=='A' or c=='E' or c=='I' or c=='O' or c=='U':\n",
+ " pv[0]+=1\n",
+ " elif c>='A' and c<='Z':\n",
+ " pc[0]+=1\n",
+ " elif c>='0' and c<='9':\n",
+ " pd[0]+=1\n",
+ " elif c==' ' or c=='\\t':\n",
+ " pw[0]+=1\n",
+ " else:\n",
+ " po[0]+=1\n",
+ "\n",
+ " return\n",
+ "\n",
+ "\n",
+ "vowel,consonants,digits,whitespc,other=[0],[0],[0],[0],[0]\n",
+ "line=\"Personal computers with memories in excess of 4096 KB are now quite common.\"\n",
+ "line=line.upper()\n",
+ "scan_line(line,vowel,consonants,digits,whitespc,other)\n",
+ "print \"\\n\\n\"\n",
+ "print \"No. of vowels : \",vowel[0]\n",
+ "print \"No. of consonants : \",consonants[0]\n",
+ "print \"No. of digits : \",digits[0]\n",
+ "print \"No. of whitespace characters : \",whitespc[0]\n",
+ "print \"No. of other characters : \",other[0]"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "\n\n\nNo. of vowels : 23\nNo. of consonants : 35\nNo. of digits : 4\nNo. of whitespace characters : 12\nNo. of other characters : 1\n"
+ "text": [
+ "\n",
+ "\n",
+ "\n",
+ "No. of vowels : 23\n",
+ "No. of consonants : 35\n",
+ "No. of digits : 4\n",
+ "No. of whitespace characters : 12\n",
+ "No. of other characters : 1\n"
+ ]
}
],
"prompt_number": 15
@@ -115,19 +244,40 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.12, Page number: 11.15<h3>"
+ "source": [
+ "<h3>Example 11.12, Page number: 11.15<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# unlike C in python the elements of a list are not arranged in memory uniformly\n\nx=[10,11,12,13,14,15,16,17,18,19]\n\nfor i in range(0,10):\n print \"i=%d x[i]=%d *(x+1)=%d\" %(i,x[i],x[i]),\n print \" &x[i]=\",id(x[i]),\n print \" x+i=\",id(x[i])",
+ "input": [
+ "\n",
+ "x=[10,11,12,13,14,15,16,17,18,19]\n",
+ "\n",
+ "for i in range(0,10):\n",
+ " print \"i=%d x[i]=%d *(x+1)=%d\" %(i,x[i],x[i]),\n",
+ " print \" &x[i]=\",id(x[i]),\n",
+ " print \" x+i=\",id(x[i])"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "i=0 x[i]=10 *(x+1)=10 &x[i]= 30696620 x+i= 30696620\ni=1 x[i]=11 *(x+1)=11 &x[i]= 30696608 x+i= 30696608\ni=2 x[i]=12 *(x+1)=12 &x[i]= 30696596 x+i= 30696596\ni=3 x[i]=13 *(x+1)=13 &x[i]= 30696584 x+i= 30696584\ni=4 x[i]=14 *(x+1)=14 &x[i]= 30696572 x+i= 30696572\ni=5 x[i]=15 *(x+1)=15 &x[i]= 30696560 x+i= 30696560\ni=6 x[i]=16 *(x+1)=16 &x[i]= 30696548 x+i= 30696548\ni=7 x[i]=17 *(x+1)=17 &x[i]= 30696536 x+i= 30696536\ni=8 x[i]=18 *(x+1)=18 &x[i]= 30696524 x+i= 30696524\ni=9 x[i]=19 *(x+1)=19 &x[i]= 30696512 x+i= 30696512\n"
+ "text": [
+ "i=0 x[i]=10 *(x+1)=10 &x[i]= 30696620 x+i= 30696620\n",
+ "i=1 x[i]=11 *(x+1)=11 &x[i]= 30696608 x+i= 30696608\n",
+ "i=2 x[i]=12 *(x+1)=12 &x[i]= 30696596 x+i= 30696596\n",
+ "i=3 x[i]=13 *(x+1)=13 &x[i]= 30696584 x+i= 30696584\n",
+ "i=4 x[i]=14 *(x+1)=14 &x[i]= 30696572 x+i= 30696572\n",
+ "i=5 x[i]=15 *(x+1)=15 &x[i]= 30696560 x+i= 30696560\n",
+ "i=6 x[i]=16 *(x+1)=16 &x[i]= 30696548 x+i= 30696548\n",
+ "i=7 x[i]=17 *(x+1)=17 &x[i]= 30696536 x+i= 30696536\n",
+ "i=8 x[i]=18 *(x+1)=18 &x[i]= 30696524 x+i= 30696524\n",
+ "i=9 x[i]=19 *(x+1)=19 &x[i]= 30696512 x+i= 30696512\n"
+ ]
}
],
"prompt_number": 16
@@ -135,19 +285,38 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.14, Page number: 11.17<h3>"
+ "source": [
+ "<h3>Example 11.14, Page number: 11.17<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# string as one dimensional character array\n\ndef main():\n global x\n y=\"This string is declared within main\"\n y=list(y)\n x=list(x)\n print x\n print y\n\n return\n\nx=\"This string is declared externally\"\nmain()\n",
+ "input": [
+ "\n",
+ "def main():\n",
+ " global x\n",
+ " y=\"This string is declared within main\"\n",
+ " y=list(y)\n",
+ " x=list(x)\n",
+ " print x\n",
+ " print y\n",
+ "\n",
+ " return\n",
+ "\n",
+ "x=\"This string is declared externally\"\n",
+ "main()\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "['T', 'h', 'i', 's', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', 'i', 's', ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ', 'e', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'l', 'y']\n['T', 'h', 'i', 's', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', 'i', 's', ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ', 'w', 'i', 't', 'h', 'i', 'n', ' ', 'm', 'a', 'i', 'n']\n"
+ "text": [
+ "['T', 'h', 'i', 's', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', 'i', 's', ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ', 'e', 'x', 't', 'e', 'r', 'n', 'a', 'l', 'l', 'y']\n",
+ "['T', 'h', 'i', 's', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', 'i', 's', ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ', 'w', 'i', 't', 'h', 'i', 'n', ' ', 'm', 'a', 'i', 'n']\n"
+ ]
}
],
"prompt_number": 17
@@ -155,19 +324,71 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.16, Page number: 11.19<h3>"
+ "source": [
+ "<h3>Example 11.16, Page number: 11.19<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Reoedering a list of numbers\n\n\ndef reorder(x):\n n=len(x)\n for item in range(0,n-1):\n for i in range(item+1,n):\n if x[i]<x[item]:\n temp=x[item]\n x[item]=x[i]\n x[i]=temp\n\n return\n\nn=10\nx=[]\n\nfor i in range(0,n):\n inp=i+1\n print \"\\ni=%d x=%d\" %(i+1,inp),\n x.append(inp)\n\nreorder(x)\n\nprint \"\\n\"\nfor i in range(0,n):\n print \"i=%d x=%d\" %(i+1,x[i])\n",
+ "input": [
+ "\n",
+ "\n",
+ "def reorder(x):\n",
+ " n=len(x)\n",
+ " for item in range(0,n-1):\n",
+ " for i in range(item+1,n):\n",
+ " if x[i]<x[item]:\n",
+ " temp=x[item]\n",
+ " x[item]=x[i]\n",
+ " x[i]=temp\n",
+ "\n",
+ " return\n",
+ "\n",
+ "n=10\n",
+ "x=[]\n",
+ "\n",
+ "for i in range(0,n):\n",
+ " inp=i+1\n",
+ " print \"\\ni=%d x=%d\" %(i+1,inp),\n",
+ " x.append(inp)\n",
+ "\n",
+ "reorder(x)\n",
+ "\n",
+ "print \"\\n\"\n",
+ "for i in range(0,n):\n",
+ " print \"i=%d x=%d\" %(i+1,x[i])\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "\ni=1 x=1 \ni=2 x=2 \ni=3 x=3 \ni=4 x=4 \ni=5 x=5 \ni=6 x=6 \ni=7 x=7 \ni=8 x=8 \ni=9 x=9 \ni=10 x=10 \n\ni=1 x=1\ni=2 x=2\ni=3 x=3\ni=4 x=4\ni=5 x=5\ni=6 x=6\ni=7 x=7\ni=8 x=8\ni=9 x=9\ni=10 x=10\n"
+ "text": [
+ "\n",
+ "i=1 x=1 \n",
+ "i=2 x=2 \n",
+ "i=3 x=3 \n",
+ "i=4 x=4 \n",
+ "i=5 x=5 \n",
+ "i=6 x=6 \n",
+ "i=7 x=7 \n",
+ "i=8 x=8 \n",
+ "i=9 x=9 \n",
+ "i=10 x=10 \n",
+ "\n",
+ "i=1 x=1\n",
+ "i=2 x=2\n",
+ "i=3 x=3\n",
+ "i=4 x=4\n",
+ "i=5 x=5\n",
+ "i=6 x=6\n",
+ "i=7 x=7\n",
+ "i=8 x=8\n",
+ "i=9 x=9\n",
+ "i=10 x=10\n"
+ ]
}
],
"prompt_number": 18
@@ -175,19 +396,40 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.17, Page number: 11.21<h3>"
+ "source": [
+ "<h3>Example 11.17, Page number: 11.21<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Pointer arithmetic doesnt exixt in python\n\ni=[4]\ni[0]=1\nf=0.3\nd=0.005\nc='*'\n\npx=i\nprint 'Values: i=%d f=%f d=%f c=%c \\n' %(i[0],f,d,c)\nprint 'Addresses: &i=%X &f=%X &d=%X &c=%X \\n' %(id(i[0]),id(f),id(d),id(c))\nprint 'Pointer Values: px=%X px+1=%X px+2=%X px+3=%X' %(id(px[0]),id(px[0]+1),id(px[0]+2),id(px[0]+3))\n\n",
+ "input": [
+ "\n",
+ "i=[4]\n",
+ "i[0]=1\n",
+ "f=0.3\n",
+ "d=0.005\n",
+ "c='*'\n",
+ "\n",
+ "px=i\n",
+ "print 'Values: i=%d f=%f d=%f c=%c \\n' %(i[0],f,d,c)\n",
+ "print 'Addresses: &i=%X &f=%X &d=%X &c=%X \\n' %(id(i[0]),id(f),id(d),id(c))\n",
+ "print 'Pointer Values: px=%X px+1=%X px+2=%X px+3=%X' %(id(px[0]),id(px[0]+1),id(px[0]+2),id(px[0]+3))\n",
+ "\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Values: i=1 f=0.300000 d=0.005000 c=* \n\nAddresses: &i=1D46518 &f=32BD940 &d=32BD950 &c=1D9F158 \n\nPointer Values: px=1D46518 px+1=1D4650C px+2=1D46500 px+3=1D464F4\n"
+ "text": [
+ "Values: i=1 f=0.300000 d=0.005000 c=* \n",
+ "\n",
+ "Addresses: &i=1D46518 &f=32BD940 &d=32BD950 &c=1D9F158 \n",
+ "\n",
+ "Pointer Values: px=1D46518 px+1=1D4650C px+2=1D46500 px+3=1D464F4\n"
+ ]
}
],
"prompt_number": 19
@@ -195,19 +437,34 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.18, Page number: 11.22<h3>"
+ "source": [
+ "<h3>Example 11.18, Page number: 11.22<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# two different pointer variable points to the first and last element of an integer array\n\na=[1,2,3,4,5,6]\n\npx=a[0]\npy=a[5]\n\nprint 'px=%X py=%X \\n' %(id(px),id(py))\nprint 'py - px = %X' %(id(py)-id(px))",
+ "input": [
+ "\n",
+ "a=[1,2,3,4,5,6]\n",
+ "\n",
+ "px=a[0]\n",
+ "py=a[5]\n",
+ "\n",
+ "print 'px=%X py=%X \\n' %(id(px),id(py))\n",
+ "print 'py - px = %X' %(id(py)-id(px))"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "px=1D46518 py=1D464DC \n\npy - px = -3C\n"
+ "text": [
+ "px=1D46518 py=1D464DC \n",
+ "\n",
+ "py - px = -3C\n"
+ ]
}
],
"prompt_number": 20
@@ -215,19 +472,96 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.22, Page number: 11.26<h3>"
+ "source": [
+ "<h3>Example 11.22, Page number: 11.26<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# adding two tables of numbers\n\ndef readinput(m,n,i=0):\n\n at=[]\n for row in range(0,m):\n temp=[]\n for col in range(0,n):\n t=i\n i+=2\n temp.append(t)\n at.append(temp)\n\n\n return at\n \ndef computesum(a,b,m,n):\n\n c=[]\n\n for row in range(0,m):\n temp=[]\n for col in range(0,n):\n t=a[row][col]+b[row][col]\n temp.append(t)\n c.append(temp)\n\n return c\n\ndef writeoutput(c,m,n):\n\n for row in range(0,m):\n for col in range(0,n):\n print \"%4d\" %(c[row][col]),\n print\n\n return\n\n\n\nprint \"\\n FIRST TABLE : \\n\"\na=readinput(5,5,1)\nwriteoutput(a,5,5)\n\nprint \"\\n SECOND TABLE : \\n\"\nb=readinput(5,5,50)\nwriteoutput(b,5,5)\n\nc=computesum(a,b,5,5)\nprint \"Sums of the elements : \\n\"\nwriteoutput(c,5,5)\n",
+ "input": [
+ "\n",
+ "def readinput(m,n,i=0):\n",
+ "\n",
+ " at=[]\n",
+ " for row in range(0,m):\n",
+ " temp=[]\n",
+ " for col in range(0,n):\n",
+ " t=i\n",
+ " i+=2\n",
+ " temp.append(t)\n",
+ " at.append(temp)\n",
+ "\n",
+ "\n",
+ " return at\n",
+ " \n",
+ "def computesum(a,b,m,n):\n",
+ "\n",
+ " c=[]\n",
+ "\n",
+ " for row in range(0,m):\n",
+ " temp=[]\n",
+ " for col in range(0,n):\n",
+ " t=a[row][col]+b[row][col]\n",
+ " temp.append(t)\n",
+ " c.append(temp)\n",
+ "\n",
+ " return c\n",
+ "\n",
+ "def writeoutput(c,m,n):\n",
+ "\n",
+ " for row in range(0,m):\n",
+ " for col in range(0,n):\n",
+ " print \"%4d\" %(c[row][col]),\n",
+ " print\n",
+ "\n",
+ " return\n",
+ "\n",
+ "\n",
+ "\n",
+ "print \"\\n FIRST TABLE : \\n\"\n",
+ "a=readinput(5,5,1)\n",
+ "writeoutput(a,5,5)\n",
+ "\n",
+ "print \"\\n SECOND TABLE : \\n\"\n",
+ "b=readinput(5,5,50)\n",
+ "writeoutput(b,5,5)\n",
+ "\n",
+ "c=computesum(a,b,5,5)\n",
+ "print \"Sums of the elements : \\n\"\n",
+ "writeoutput(c,5,5)\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "\n FIRST TABLE : \n\n 1 3 5 7 9\n 11 13 15 17 19\n 21 23 25 27 29\n 31 33 35 37 39\n 41 43 45 47 49\n\n SECOND TABLE : \n\n 50 52 54 56 58\n 60 62 64 66 68\n 70 72 74 76 78\n 80 82 84 86 88\n 90 92 94 96 98\nSums of the elements : \n\n 51 55 59 63 67\n 71 75 79 83 87\n 91 95 99 103 107\n 111 115 119 123 127\n 131 135 139 143 147\n"
+ "text": [
+ "\n",
+ " FIRST TABLE : \n",
+ "\n",
+ " 1 3 5 7 9\n",
+ " 11 13 15 17 19\n",
+ " 21 23 25 27 29\n",
+ " 31 33 35 37 39\n",
+ " 41 43 45 47 49\n",
+ "\n",
+ " SECOND TABLE : \n",
+ "\n",
+ " 50 52 54 56 58\n",
+ " 60 62 64 66 68\n",
+ " 70 72 74 76 78\n",
+ " 80 82 84 86 88\n",
+ " 90 92 94 96 98\n",
+ "Sums of the elements : \n",
+ "\n",
+ " 51 55 59 63 67\n",
+ " 71 75 79 83 87\n",
+ " 91 95 99 103 107\n",
+ " 111 115 119 123 127\n",
+ " 131 135 139 143 147\n"
+ ]
}
],
"prompt_number": 21
@@ -235,19 +569,96 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.24, Page number: 11.31<h3>"
+ "source": [
+ "<h3>Example 11.24, Page number: 11.31<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# adding two tables of numbers\n\ndef readinput(m,n,i=0):\n\n at=[]\n for row in range(0,m):\n temp=[]\n for col in range(0,n):\n t=i\n i+=2\n temp.append(t)\n at.append(temp)\n\n\n return at\n \ndef computesum(a,b,m,n):\n\n c=[]\n\n for row in range(0,m):\n temp=[]\n for col in range(0,n):\n t=a[row][col]+b[row][col]\n temp.append(t)\n c.append(temp)\n\n return c\n\ndef writeoutput(c,m,n):\n\n for row in range(0,m):\n for col in range(0,n):\n print \"%4d\" %(c[row][col]),\n print\n\n return\n\n\n\nprint \"\\n FIRST TABLE : \\n\"\na=readinput(5,5,1)\nwriteoutput(a,5,5)\n\nprint \"\\n SECOND TABLE : \\n\"\nb=readinput(5,5,50)\nwriteoutput(b,5,5)\n\nc=computesum(a,b,5,5)\nprint \"Sums of the elements : \\n\"\nwriteoutput(c,5,5)\n",
+ "input": [
+ "\n",
+ "def readinput(m,n,i=0):\n",
+ "\n",
+ " at=[]\n",
+ " for row in range(0,m):\n",
+ " temp=[]\n",
+ " for col in range(0,n):\n",
+ " t=i\n",
+ " i+=2\n",
+ " temp.append(t)\n",
+ " at.append(temp)\n",
+ "\n",
+ "\n",
+ " return at\n",
+ " \n",
+ "def computesum(a,b,m,n):\n",
+ "\n",
+ " c=[]\n",
+ "\n",
+ " for row in range(0,m):\n",
+ " temp=[]\n",
+ " for col in range(0,n):\n",
+ " t=a[row][col]+b[row][col]\n",
+ " temp.append(t)\n",
+ " c.append(temp)\n",
+ "\n",
+ " return c\n",
+ "\n",
+ "def writeoutput(c,m,n):\n",
+ "\n",
+ " for row in range(0,m):\n",
+ " for col in range(0,n):\n",
+ " print \"%4d\" %(c[row][col]),\n",
+ " print\n",
+ "\n",
+ " return\n",
+ "\n",
+ "\n",
+ "\n",
+ "print \"\\n FIRST TABLE : \\n\"\n",
+ "a=readinput(5,5,1)\n",
+ "writeoutput(a,5,5)\n",
+ "\n",
+ "print \"\\n SECOND TABLE : \\n\"\n",
+ "b=readinput(5,5,50)\n",
+ "writeoutput(b,5,5)\n",
+ "\n",
+ "c=computesum(a,b,5,5)\n",
+ "print \"Sums of the elements : \\n\"\n",
+ "writeoutput(c,5,5)\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "\n FIRST TABLE : \n\n 1 3 5 7 9\n 11 13 15 17 19\n 21 23 25 27 29\n 31 33 35 37 39\n 41 43 45 47 49\n\n SECOND TABLE : \n\n 50 52 54 56 58\n 60 62 64 66 68\n 70 72 74 76 78\n 80 82 84 86 88\n 90 92 94 96 98\nSums of the elements : \n\n 51 55 59 63 67\n 71 75 79 83 87\n 91 95 99 103 107\n 111 115 119 123 127\n 131 135 139 143 147\n"
+ "text": [
+ "\n",
+ " FIRST TABLE : \n",
+ "\n",
+ " 1 3 5 7 9\n",
+ " 11 13 15 17 19\n",
+ " 21 23 25 27 29\n",
+ " 31 33 35 37 39\n",
+ " 41 43 45 47 49\n",
+ "\n",
+ " SECOND TABLE : \n",
+ "\n",
+ " 50 52 54 56 58\n",
+ " 60 62 64 66 68\n",
+ " 70 72 74 76 78\n",
+ " 80 82 84 86 88\n",
+ " 90 92 94 96 98\n",
+ "Sums of the elements : \n",
+ "\n",
+ " 51 55 59 63 67\n",
+ " 71 75 79 83 87\n",
+ " 91 95 99 103 107\n",
+ " 111 115 119 123 127\n",
+ " 131 135 139 143 147\n"
+ ]
}
],
"prompt_number": 22
@@ -255,19 +666,77 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.26, Page number: 11.34<h3>"
+ "source": [
+ "<h3>Example 11.26, Page number: 11.34<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Reordering a list of strings\n\n\ndef reorder(x):\n\n n=len(x)\n for item in range(0,n-1):\n for i in range(item+1,n):\n if x[item]>x[i]:\n temp=x[item]\n x[item]=x[i]\n x[i]=temp\n\n\n return\n\nx=['PACIFIC','ATLANTIC','INDIAN','CARIBBEAN','BERING','BLACK','RED','NORTH','BALTIC','CASPIAN']\nprint 'Original list of strings :\\n\\n'\n\nfor i in x:\n print \"String : \",i\n\nreorder(x)\n\nprint \"\\nReodered list of strings : \\n\\n\"\n\nfor i in x:\n print \"String : \",i",
+ "input": [
+ "\n",
+ "\n",
+ "def reorder(x):\n",
+ "\n",
+ " n=len(x)\n",
+ " for item in range(0,n-1):\n",
+ " for i in range(item+1,n):\n",
+ " if x[item]>x[i]:\n",
+ " temp=x[item]\n",
+ " x[item]=x[i]\n",
+ " x[i]=temp\n",
+ "\n",
+ "\n",
+ " return\n",
+ "\n",
+ "x=['PACIFIC','ATLANTIC','INDIAN','CARIBBEAN','BERING','BLACK','RED','NORTH','BALTIC','CASPIAN']\n",
+ "print 'Original list of strings :\\n\\n'\n",
+ "\n",
+ "for i in x:\n",
+ " print \"String : \",i\n",
+ "\n",
+ "reorder(x)\n",
+ "\n",
+ "print \"\\nReodered list of strings : \\n\\n\"\n",
+ "\n",
+ "for i in x:\n",
+ " print \"String : \",i"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Original list of strings :\n\n\nString : PACIFIC\nString : ATLANTIC\nString : INDIAN\nString : CARIBBEAN\nString : BERING\nString : BLACK\nString : RED\nString : NORTH\nString : BALTIC\nString : CASPIAN\n\nReodered list of strings : \n\n\nString : ATLANTIC\nString : BALTIC\nString : BERING\nString : BLACK\nString : CARIBBEAN\nString : CASPIAN\nString : INDIAN\nString : NORTH\nString : PACIFIC\nString : RED\n"
+ "text": [
+ "Original list of strings :\n",
+ "\n",
+ "\n",
+ "String : PACIFIC\n",
+ "String : ATLANTIC\n",
+ "String : INDIAN\n",
+ "String : CARIBBEAN\n",
+ "String : BERING\n",
+ "String : BLACK\n",
+ "String : RED\n",
+ "String : NORTH\n",
+ "String : BALTIC\n",
+ "String : CASPIAN\n",
+ "\n",
+ "Reodered list of strings : \n",
+ "\n",
+ "\n",
+ "String : ATLANTIC\n",
+ "String : BALTIC\n",
+ "String : BERING\n",
+ "String : BLACK\n",
+ "String : CARIBBEAN\n",
+ "String : CASPIAN\n",
+ "String : INDIAN\n",
+ "String : NORTH\n",
+ "String : PACIFIC\n",
+ "String : RED\n"
+ ]
}
],
"prompt_number": 23
@@ -275,19 +744,79 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.28, Page number: 11.37<h3>"
+ "source": [
+ "<h3>Example 11.28, Page number: 11.37<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Display the day of the year\n\n\ndef convert(mm,dd,yy):\n yy-=1900\n ndays=long(30.42*(mm-1)+dd)\n if mm==2:\n ndays+=1\n if mm>2 and mm<8:\n ndays-=1\n if yy%4==0 and mm<2:\n ndays+=1\n\n ncycles=yy/4\n ndays+=ncycles*1461\n\n nyears=yy%4\n if nyears>0:\n ndays+=365*nyears+1\n if ndays>59:\n ndays-=1\n\n day=ndays%7\n\n return day\n\ndef main(mm,dd,yy):\n day_of_week=convert(mm,dd,yy)\n print \"%s, %s %d %d\" %(weekday[day_of_week],month[mm-1],dd,yy)\n return\n \nweekday=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\nmonth=['January','February','March','April','May','June','July','August',\\\n 'September','October','November','December']\n\nmain(10,29,1929)\nprint\nmain(8,15,1945)\nprint\nmain(7,20,1969)\nprint\nmain(5,24,1997)\nprint\nmain(8,30,2010)\nprint\nmain(4,12,2069)\n",
+ "input": [
+ "\n",
+ "\n",
+ "def convert(mm,dd,yy):\n",
+ " yy-=1900\n",
+ " ndays=long(30.42*(mm-1)+dd)\n",
+ " if mm==2:\n",
+ " ndays+=1\n",
+ " if mm>2 and mm<8:\n",
+ " ndays-=1\n",
+ " if yy%4==0 and mm<2:\n",
+ " ndays+=1\n",
+ "\n",
+ " ncycles=yy/4\n",
+ " ndays+=ncycles*1461\n",
+ "\n",
+ " nyears=yy%4\n",
+ " if nyears>0:\n",
+ " ndays+=365*nyears+1\n",
+ " if ndays>59:\n",
+ " ndays-=1\n",
+ "\n",
+ " day=ndays%7\n",
+ "\n",
+ " return day\n",
+ "\n",
+ "def main(mm,dd,yy):\n",
+ " day_of_week=convert(mm,dd,yy)\n",
+ " print \"%s, %s %d %d\" %(weekday[day_of_week],month[mm-1],dd,yy)\n",
+ " return\n",
+ " \n",
+ "weekday=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\n",
+ "month=['January','February','March','April','May','June','July','August',\\\n",
+ " 'September','October','November','December']\n",
+ "\n",
+ "main(10,29,1929)\n",
+ "print\n",
+ "main(8,15,1945)\n",
+ "print\n",
+ "main(7,20,1969)\n",
+ "print\n",
+ "main(5,24,1997)\n",
+ "print\n",
+ "main(8,30,2010)\n",
+ "print\n",
+ "main(4,12,2069)\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Tuesday, October 29 1929\n\nWednesday, August 15 1945\n\nSunday, July 20 1969\n\nSaturday, May 24 1997\n\nMonday, August 30 2010\n\nFriday, April 12 2069\n"
+ "text": [
+ "Tuesday, October 29 1929\n",
+ "\n",
+ "Wednesday, August 15 1945\n",
+ "\n",
+ "Sunday, July 20 1969\n",
+ "\n",
+ "Saturday, May 24 1997\n",
+ "\n",
+ "Monday, August 30 2010\n",
+ "\n",
+ "Friday, April 12 2069\n"
+ ]
}
],
"prompt_number": 24
@@ -295,19 +824,139 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 11.30, Page number: 11.44<h3>"
+ "source": [
+ "<h3>Example 11.30, Page number: 11.44<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "# Future value of monthly deposits (compound interest calculations)\n\n\ndef ratio_choose(freq,a,m,n):\n\n if freq=='C':\n ratio=md3(a,m,n)\n elif freq=='D':\n ratio=md2(a,m,n)\n else:\n ratio=md1(a,m,n)\n\n return ratio\n\n\ndef table(freq,a,m,n):\n\n\n print \"Interest Rate Future Amount\\n\\n\"\n for count in range(1,21):\n i=0.01*count\n f=a*ratio_choose(freq,i,m,n)\n print \" %2d %.2f\" %(count,f)\n\n return\n\ndef md1(i,m,n):\n \n factor=1+i/m\n ratio=12*(factor**(m*n)-1)/i\n return ratio\n\ndef md2(i,m,n):\n\n factor=1+i/m\n ratio=(factor**(m*n)-1)/(factor**(m/12)-1)\n return ratio\n\ndef md3(i,dummy,n):\n ratio=(10**(i*n)-1)/(10**(i/12)-1)\n return ratio\n\ndef main(freq):\n m=0\n freq=freq.upper()\n if freq=='A':\n m=1\n print \"\\nAnual Compounding\\n\"\n \n elif freq=='S':\n m=2\n print \"\\nSemiannual Compounding\\n\"\n \n elif freq=='Q':\n print \"\\nQuaterly Compounding\\n\"\n m=4\n \n elif freq=='M':\n m=12\n print \"\\nMonthly Compounding\\n\"\n \n elif freq=='D':\n m=360\n print \"\\nDaily Compounding\\n\"\n\n elif freq=='C':\n m=0\n print \"\\nContinuous Compounding\\n\"\n \n else:\n print \"\\nERROR!!! Please Repeat\\n\\n\"\n return\n \n return m\n\n\na,n,freq=100,3,'m'\nprint \"FUTURE VALUE OF A SERIES OF MONTHLY DEPOSITS\\n\\n\"\nprint \"Frequency of Compunding (A,S,Q,M,D,C): \",freq\nprint \"Amount of Each Monthly Payement : \",a\nprint \"Number of years: \",n\nm=main(freq)\n\ntable(freq,a,m,n)\n\n",
+ "input": [
+ "\n",
+ "\n",
+ "def ratio_choose(freq,a,m,n):\n",
+ "\n",
+ " if freq=='C':\n",
+ " ratio=md3(a,m,n)\n",
+ " elif freq=='D':\n",
+ " ratio=md2(a,m,n)\n",
+ " else:\n",
+ " ratio=md1(a,m,n)\n",
+ "\n",
+ " return ratio\n",
+ "\n",
+ "\n",
+ "def table(freq,a,m,n):\n",
+ "\n",
+ "\n",
+ " print \"Interest Rate Future Amount\\n\\n\"\n",
+ " for count in range(1,21):\n",
+ " i=0.01*count\n",
+ " f=a*ratio_choose(freq,i,m,n)\n",
+ " print \" %2d %.2f\" %(count,f)\n",
+ "\n",
+ " return\n",
+ "\n",
+ "def md1(i,m,n):\n",
+ " \n",
+ " factor=1+i/m\n",
+ " ratio=12*(factor**(m*n)-1)/i\n",
+ " return ratio\n",
+ "\n",
+ "def md2(i,m,n):\n",
+ "\n",
+ " factor=1+i/m\n",
+ " ratio=(factor**(m*n)-1)/(factor**(m/12)-1)\n",
+ " return ratio\n",
+ "\n",
+ "def md3(i,dummy,n):\n",
+ " ratio=(10**(i*n)-1)/(10**(i/12)-1)\n",
+ " return ratio\n",
+ "\n",
+ "def main(freq):\n",
+ " m=0\n",
+ " freq=freq.upper()\n",
+ " if freq=='A':\n",
+ " m=1\n",
+ " print \"\\nAnual Compounding\\n\"\n",
+ " \n",
+ " elif freq=='S':\n",
+ " m=2\n",
+ " print \"\\nSemiannual Compounding\\n\"\n",
+ " \n",
+ " elif freq=='Q':\n",
+ " print \"\\nQuaterly Compounding\\n\"\n",
+ " m=4\n",
+ " \n",
+ " elif freq=='M':\n",
+ " m=12\n",
+ " print \"\\nMonthly Compounding\\n\"\n",
+ " \n",
+ " elif freq=='D':\n",
+ " m=360\n",
+ " print \"\\nDaily Compounding\\n\"\n",
+ "\n",
+ " elif freq=='C':\n",
+ " m=0\n",
+ " print \"\\nContinuous Compounding\\n\"\n",
+ " \n",
+ " else:\n",
+ " print \"\\nERROR!!! Please Repeat\\n\\n\"\n",
+ " return\n",
+ " \n",
+ " return m\n",
+ "\n",
+ "\n",
+ "a,n,freq=100,3,'m'\n",
+ "print \"FUTURE VALUE OF A SERIES OF MONTHLY DEPOSITS\\n\\n\"\n",
+ "print \"Frequency of Compunding (A,S,Q,M,D,C): \",freq\n",
+ "print \"Amount of Each Monthly Payement : \",a\n",
+ "print \"Number of years: \",n\n",
+ "m=main(freq)\n",
+ "\n",
+ "table(freq,a,m,n)\n",
+ "\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "FUTURE VALUE OF A SERIES OF MONTHLY DEPOSITS\n\n\nFrequency of Compunding (A,S,Q,M,D,C): m\nAmount of Each Monthly Payement : 100\nNumber of years: 3\n\nMonthly Compounding\n\nInterest Rate Future Amount\n\n\n 1 3653.00\n 2 3707.01\n 3 3762.06\n 4 3818.16\n 5 3875.33\n 6 3933.61\n 7 3993.01\n 8 4053.56\n 9 4115.27\n 10 4178.18\n 11 4242.31\n 12 4307.69\n 13 4374.33\n 14 4442.28\n 15 4511.55\n 16 4582.17\n 17 4654.18\n 18 4727.60\n 19 4802.45\n 20 4878.78\n"
+ "text": [
+ "FUTURE VALUE OF A SERIES OF MONTHLY DEPOSITS\n",
+ "\n",
+ "\n",
+ "Frequency of Compunding (A,S,Q,M,D,C): m\n",
+ "Amount of Each Monthly Payement : 100\n",
+ "Number of years: 3\n",
+ "\n",
+ "Monthly Compounding\n",
+ "\n",
+ "Interest Rate Future Amount\n",
+ "\n",
+ "\n",
+ " 1 3653.00\n",
+ " 2 3707.01\n",
+ " 3 3762.06\n",
+ " 4 3818.16\n",
+ " 5 3875.33\n",
+ " 6 3933.61\n",
+ " 7 3993.01\n",
+ " 8 4053.56\n",
+ " 9 4115.27\n",
+ " 10 4178.18\n",
+ " 11 4242.31\n",
+ " 12 4307.69\n",
+ " 13 4374.33\n",
+ " 14 4442.28\n",
+ " 15 4511.55\n",
+ " 16 4582.17\n",
+ " 17 4654.18\n",
+ " 18 4727.60\n",
+ " 19 4802.45\n",
+ " 20 4878.78\n"
+ ]
}
],
"prompt_number": 25
@@ -315,7 +964,7 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "",
+ "input": [],
"language": "python",
"metadata": {},
"outputs": [],
diff --git a/_Programming_With_C/chapter12.ipynb b/_Programming_With_C/chapter12.ipynb
index 8cde425c..09e4c7e9 100644
--- a/_Programming_With_C/chapter12.ipynb
+++ b/_Programming_With_C/chapter12.ipynb
@@ -115,7 +115,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Updating Costumer Records\n",
"from ctypes import *\n",
"\n",
"string=c_char*50\n",
@@ -315,7 +314,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# To process a linked List of strings\n",
"\n",
"class node():\n",
"\t\n",
@@ -457,7 +455,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Raising a number to a power\n",
"\n",
"from ctypes import *\n",
"import math\n",
diff --git a/_Programming_With_C/chapter13.ipynb b/_Programming_With_C/chapter13.ipynb
index fca3666f..fe4b86df 100644
--- a/_Programming_With_C/chapter13.ipynb
+++ b/_Programming_With_C/chapter13.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Writing to a data file\n",
"\n",
"fp=open(\"output.txt\",'w')\n",
"for k in range(65,91):\n",
@@ -50,7 +49,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Creating a file containing customer records\n",
"\n",
"from ctypes import *\n",
"\n",
@@ -154,7 +152,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# concept of binary files\n",
"\n",
"fp=open('binval.txt','wb')\n",
"\n",
diff --git a/_Programming_With_C/chapter14.ipynb b/_Programming_With_C/chapter14.ipynb
index 325040e9..d89e7c72 100644
--- a/_Programming_With_C/chapter14.ipynb
+++ b/_Programming_With_C/chapter14.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of right shift operator\n",
"\n",
"a=0xf05a\n",
"\n",
@@ -57,7 +56,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# displaying bit patterns\n",
"\n",
"\n",
"a=1\n",
@@ -129,7 +127,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Storing Names and Birthdays\n",
"\n",
"from ctypes import *\n",
"\n",
diff --git a/_Programming_With_C/chapter2.ipynb b/_Programming_With_C/chapter2.ipynb
index 8b81d936..178b56ae 100644
--- a/_Programming_With_C/chapter2.ipynb
+++ b/_Programming_With_C/chapter2.ipynb
@@ -52,7 +52,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# for adding two numbers\n",
"\n",
"\n",
"sum=10+20\n",
@@ -83,7 +82,6 @@
"collapsed": false,
"input": [
"\n",
- "# to find the sum. numbers taken as input\n",
"\n",
"\n",
"num1,num2=50,25\n",
diff --git a/_Programming_With_C/chapter3.ipynb b/_Programming_With_C/chapter3.ipynb
index b9600cd8..fbf10f10 100644
--- a/_Programming_With_C/chapter3.ipynb
+++ b/_Programming_With_C/chapter3.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#illustrates the size of respective data type (in C)\n",
"\n",
"import ctypes as ct\n",
"\n",
@@ -62,7 +61,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# to calculate the roots of quadratic equation\n",
"\n",
"\n",
"print \"for the equation ax^2+bx+c \\n\"\n",
@@ -106,7 +104,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# to convert a lower case char to upper case\n",
"\n",
"\n",
"\n",
diff --git a/_Programming_With_C/chapter4.ipynb b/_Programming_With_C/chapter4.ipynb
index 1f1dcee7..21edac6f 100644
--- a/_Programming_With_C/chapter4.ipynb
+++ b/_Programming_With_C/chapter4.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# lowercase to uppercase conversion\n",
"\n",
"\n",
"ch='a'\n",
@@ -55,7 +54,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# shows the use of print function\n",
"\n",
"import math\n",
"\n",
@@ -87,7 +85,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# generates the same floating point output in 2 different ways\n",
"\n",
"x,y=5000.0,0.0025\n",
"\n",
@@ -122,7 +119,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# reading and writing a line of text\n",
"\n",
"line=\"The PITTSBURG STEELERS is one of America's favorite football teams!\"\n",
"print \"%s\" %(line)\n",
@@ -152,7 +148,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of the minimum field width feature\n",
"\n",
"i=12345\n",
"x=345.678\n",
@@ -190,7 +185,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# makes use of g-type conversion\n",
"\n",
"i=12345\n",
"x=345.678\n",
@@ -230,7 +224,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of precision feature with floating points\n",
"\n",
"x=123.456\n",
"\n",
@@ -265,7 +258,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# displays floating points numbers with only precision specification\n",
"\n",
"\n",
"x=123.456\n",
@@ -301,7 +293,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of field width and precision specifications with string\n",
"\n",
"line=\"hexadecimal\"\n",
"\n",
@@ -333,7 +324,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of upper case conversion characters\n",
"\n",
"a=0x80ec\n",
"b=0.3e-12\n",
@@ -370,7 +360,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use of flags with integers and floating point quantities\n",
"\n",
"i,x,y=123,12.0,-3.3\n",
"\n",
@@ -378,7 +367,6 @@
"print \":%-6d %-7.0f %-10.1e: \\n\" %(i,x,y)\n",
"print \":%+6d %+7.0f %+10.1e: \\n\" %(i,x,y)\n",
"print \":%-+6d %-+7.0f %-+10.1e: \\n\" %(i,x,y)\n",
- "print \":%7.0f %#7.0f %7g %#7g: \\n\" %(x,x,y,y)\n",
"\n",
"\n"
],
@@ -415,13 +403,11 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# use of flags with unsigned decimal octal and hexadecimal numbers\n",
"\n",
"i,j,k=1234,01777,0xa08c\n",
"\n",
"print \":%8u %8o %8x:\\n\" %(i,j,k)\n",
"print \":%-8u %-8o %-8x:\\n\" %(i,j,k)\n",
- "print \":%#8u %#8o %#8x:\\n\" %(i,j,k)\n",
"print \":%08u %08o %08x:\\n\" %(i,j,k)\n",
"\n",
"\n",
@@ -458,7 +444,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates the use flags with strings\n",
"\n",
"line=\"lower-case\"\n",
"\n",
@@ -494,7 +479,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# illustrates how printed ouput can be labeled\n",
"\n",
"a,b,x1,x2=2.2,-6.2,0.005,-12.88\n",
"\n",
@@ -529,7 +513,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# averaging student exam scores\n",
"\n",
"\n",
"name=\"Robert Smith\"\n",
diff --git a/_Programming_With_C/chapter5.ipynb b/_Programming_With_C/chapter5.ipynb
index b76ef801..ea09f2bd 100644
--- a/_Programming_With_C/chapter5.ipynb
+++ b/_Programming_With_C/chapter5.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#Compound Interest\n",
"\n",
"import math\n",
"\n",
@@ -59,7 +58,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#Real Rppts of a Quadratic Equation\n",
"\n",
"import math\n",
"\n",
diff --git a/_Programming_With_C/chapter6.ipynb b/_Programming_With_C/chapter6.ipynb
index 9e6277c3..5da628a1 100644
--- a/_Programming_With_C/chapter6.ipynb
+++ b/_Programming_With_C/chapter6.ipynb
@@ -66,7 +66,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# understanding basic if statement\n",
"\n",
"\n",
"def main(first,second):\n",
@@ -110,7 +109,6 @@
"collapsed": false,
"input": [
"\n",
- "# to understand the use of if else\n",
"\n",
"def main(time):\n",
"\n",
@@ -157,7 +155,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# consecutive integer quantities using WHILE loop\n",
"\n",
"\n",
"digit=0\n",
@@ -199,7 +196,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# lowercase to uppercase text conversion using WHILE loop\n",
"\n",
"\n",
"\n",
@@ -239,7 +235,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# averaging a list of numbers using while loop equivalent\n",
"\n",
"Sum,count=0,0\n",
"\n",
@@ -299,7 +294,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# consecutive integer quantities using an equivalent to DO-WHILE loop\n",
"\n",
"\n",
"digit=0\n",
@@ -343,7 +337,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# lowercase to uppercase text conversion using equivalent to DO-WHILE loop\n",
"\n",
"\n",
"letter=\"Fourscore and seven years ago aou fathers brought forth...\"\n",
@@ -386,7 +379,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# averaging a list of numbers using do whileloop equivalent\n",
"\n",
"Sum,count=0,0\n",
"\n",
@@ -435,7 +427,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# consecutive integer quantities using FOR loop\n",
"\n",
"for digit in range(0,10):\n",
" print digit\n",
@@ -475,7 +466,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# lowercase to uppercase text conversion using FOR loop\n",
"\n",
"\n",
"letter=\"Fourscore and seven years ago aou fathers brought forth...\"\n",
@@ -515,7 +505,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Averaging a List of Numbers using an FOR loop\n",
"\n",
"\n",
"n=6\n",
@@ -552,7 +541,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Repeated averaging of a list of numbers\n",
"\n",
"\n",
"\n",
@@ -611,7 +599,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# coverting several lines of text to upper case\n",
"\n",
"text=['Now is the time for all good men to come to aid..','Fourscore and seven years ago our fathers brought forth...','*']\n",
"\n",
@@ -669,7 +656,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Encoding a string of characters\n",
"\n",
"line=\"The White House. 1600 Pennsylvania Avenue. Washington. DC\"\n",
"line=list(line)\n",
@@ -718,7 +704,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Repeated Compund Interest Calculations with Error Tapping\n",
"\n",
"\n",
"def main(p,r,n):\n",
@@ -764,7 +749,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Solution of an algebraic equation : x^5+3x^2-10=0\n",
"\n",
"import math\n",
"\n",
@@ -850,7 +834,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# to show equivalent of switch case in python\n",
"\n",
"def main(ch):\n",
"\n",
@@ -896,7 +879,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# a small variation to the previous example\n",
"\n",
"def main(ch):\n",
" ch=ch.upper()\n",
@@ -948,7 +930,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# another example to show th equivalent of switch case in python\n",
"\n",
"\n",
"import math\n",
@@ -1007,7 +988,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Calculating Depreciation\n",
"\n",
"choice=0\n",
"\n",
@@ -1145,7 +1125,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Averaging list of Nonnegative Numbers\n",
"\n",
"navg=0\n",
"Sum=0.0\n",
@@ -1187,7 +1166,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Searching for Palindromes\n",
"\n",
"\n",
"\n",
@@ -1250,7 +1228,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# coverting several lines of text to upper case\n",
"\n",
"text=['Now is the time for all good men to come to aid..','Fourscore and seven years ago our fathers brought forth.$$..','*']\n",
"\n",
diff --git a/_Programming_With_C/chapter7.ipynb b/_Programming_With_C/chapter7.ipynb
index e33dc0cb..89247348 100644
--- a/_Programming_With_C/chapter7.ipynb
+++ b/_Programming_With_C/chapter7.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# lowercase to uppercase character conversion\n",
"\n",
"\n",
"def lower_to_upper(c1):\n",
@@ -67,7 +66,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# a variation to the function appeared in example 7.1\n",
"\n",
"\n",
"def lower_to_upper(c1):\n",
@@ -107,7 +105,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# determine the larger of the two integer quantities\n",
"\n",
"\n",
"def maximum(x,y):\n",
@@ -151,7 +148,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# calculates the factorial of n\n",
"\n",
"\n",
"def factorial(n):\n",
@@ -190,7 +186,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# finds max\n",
"\n",
"\n",
"def maximum(x,y):\n",
@@ -231,7 +226,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Largest of the three quantities\n",
"\n",
"\n",
"def maximum(x,y):\n",
@@ -275,7 +269,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# calculates the factorial of n\n",
"\n",
"\n",
"def factorial(n):\n",
@@ -315,7 +308,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Simulation of a game of chance (shooting craps)\n",
"\n",
"\n",
"\n",
@@ -397,7 +389,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# function that alters the value of the argument\n",
"\n",
"\n",
"def modify(a):\n",
@@ -438,7 +429,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# calculating depreciation\n",
"\n",
"\n",
"def sl(val,n):\n",
@@ -596,7 +586,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# calculating factorials in recursive way\n",
"\n",
"\n",
"def factorial(n):\n",
@@ -636,7 +625,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Printing Backwards: (recrsive)\n",
"\n",
"def reverse(text,n):\n",
"\n",
@@ -677,7 +665,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# the Towers of Hanoi - using recursion\n",
"\n",
"\n",
"def transfer(n,From,to,temp):\n",
diff --git a/_Programming_With_C/chapter8.ipynb b/_Programming_With_C/chapter8.ipynb
index 398a8b23..e9a55558 100644
--- a/_Programming_With_C/chapter8.ipynb
+++ b/_Programming_With_C/chapter8.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#calculating factorials\n",
"\n",
"def factorial(n):\n",
"\t\n",
@@ -68,7 +67,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Average Length of Several Lines of Text\n",
"\n",
"def linecount(text):\n",
"\t\n",
@@ -111,7 +109,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#Search for a Maximum\n",
"\n",
"import math\n",
"\n",
@@ -178,7 +175,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Average Length of Several Lines of Text\n",
"\n",
"\n",
"def linecount(text):\n",
@@ -223,7 +219,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Generating Fibonacci Numbers\n",
"\n",
"def fibonacci(count):\n",
"\t\n",
@@ -295,7 +290,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Simulation of a game of chance (shooting craps)\n",
"\n",
"\n",
"\n",
@@ -378,7 +372,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#Search for a Maximum\n",
"\n",
"import math\n",
"\n",
@@ -444,7 +437,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Generating Fibonacci Numbers\n",
"\n",
"def fibonacci(count):\n",
"\t\n",
@@ -526,7 +518,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#Compound Interest\n",
"\n",
"import math\n",
"\n",
diff --git a/_Programming_With_C/chapter9.ipynb b/_Programming_With_C/chapter9.ipynb
index 4fbffbe5..00db2e74 100644
--- a/_Programming_With_C/chapter9.ipynb
+++ b/_Programming_With_C/chapter9.ipynb
@@ -25,7 +25,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Lowercase to uppercase text conversion\n",
"\n",
"letter='heavenly feeling'\n",
"letter=list(letter)\n",
@@ -57,7 +56,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Deviations about an average\n",
"\n",
"\n",
"Sum=0.0\n",
@@ -113,7 +111,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Deviations about an average revisited\n",
"\n",
"\n",
"n=5\n",
@@ -168,7 +165,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# passing a three element array to a function where array elements are altered\n",
"\n",
"def modify(a):\n",
" print \"From the function after modifying the values: \"\n",
@@ -226,7 +222,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# use of global variable and transfer of of local and an array to a function\n",
"\n",
"\n",
"a=1\n",
@@ -302,7 +297,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# Reordering a list of numbers\n",
"\n",
"\n",
"def reorder(n,x):\n",
@@ -379,7 +373,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# a piglatin generator\n",
"\n",
"def countwords(english):\n",
" words=1\n",
@@ -467,7 +460,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "# adding two tables of numbers\n",
"\n",
"\n",
"\n",