summaryrefslogtreecommitdiff
path: root/Programming_in_C/Chapter_10.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Programming_in_C/Chapter_10.ipynb')
-rw-r--r--Programming_in_C/Chapter_10.ipynb60
1 files changed, 0 insertions, 60 deletions
diff --git a/Programming_in_C/Chapter_10.ipynb b/Programming_in_C/Chapter_10.ipynb
index 1ec5bf12..0486f4f9 100644
--- a/Programming_in_C/Chapter_10.ipynb
+++ b/Programming_in_C/Chapter_10.ipynb
@@ -27,13 +27,9 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.1.py\n",
- "#Concatenating Character Arrays\n",
"\n",
- "#Import system library\n",
"import sys\n",
"\n",
- "#Function to concatinate strings\n",
"def concat(result,str1,n1,str2,n2): #Calculations\n",
" \n",
" #copy str1 to result\n",
@@ -45,7 +41,6 @@
" result[n1+j]=str2[j]\n",
"\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #List Declaration\n",
@@ -61,7 +56,6 @@
" sys.stdout.write(\"\\n\")\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -90,18 +84,14 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.2.py\n",
- "#Counting the Characters in a String\n",
"\n",
"\n",
- "#FUnction to count number of characters ina string\n",
"def stringLength(string):\n",
" count = 0\n",
" while(string[count]!='\\0'): #Calculation\n",
" count+=1\n",
" return count\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #List Declaration\n",
@@ -113,7 +103,6 @@
" print(\"{0} {1} {2}\\n\".format(stringLength (word1),stringLength (word2),stringLength (word3)))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -143,11 +132,8 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.3.py\n",
- "#Concatenating Character Strings\n",
"\n",
"\n",
- "#Function to concatinate strings\n",
"def concat(result,str1,str2): #Calculations\n",
" \n",
" #copy str1 to result\n",
@@ -159,7 +145,6 @@
" result.append(j)\n",
" \n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #String Declaration\n",
@@ -171,7 +156,6 @@
" print(''.join(s3)) #Result\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -200,10 +184,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.4.py\n",
- "#Testing Strings for Equality\n",
"\n",
- "#Function to compare 2 strings\n",
"def equalStrings(s1,s2):\n",
" \n",
" #Calculation\n",
@@ -227,7 +208,6 @@
" print(\"{0}\".format(equalStrings (strb, \"string\")))\n",
"\n",
"\n",
- "#Setting top level confditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -258,10 +238,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.5.py\n",
- "#Reading Strings\n",
"\n",
- "#Main()\n",
"def main():\n",
" print(\"Enter Text:\\n\")\n",
"\n",
@@ -274,7 +251,6 @@
" print(\"\\ns1={0}\\ns2={1}\\ns3={2}\\n\".format(s1,s2,s3))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -309,10 +285,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.6.py\n",
- "#Reading Lines of Data\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #List declaration\n",
@@ -322,7 +295,6 @@
" print(\"{0}\\n\".format(''.join(line))) #Result\n",
"\n",
"\n",
- "#Function to read user input\n",
"def readLine(line):\n",
" \n",
" line.pop()\n",
@@ -330,7 +302,6 @@
" #line.append(raw_input()+\" \")\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -364,10 +335,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.7.py\n",
- "#Counting Words\n",
"\n",
- "#Function to determine if a character is alphabetic\n",
"def alphabetic(c):\n",
" if ( (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z') ):\n",
" return True\n",
@@ -375,7 +343,6 @@
" return False\n",
"\n",
"\n",
- "#Function to count the number of words in a string\n",
"def countWords(string):\n",
" \n",
" #Variable Declaration\n",
@@ -393,7 +360,6 @@
" return wordCount\n",
"\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #String Declaration\n",
@@ -405,7 +371,6 @@
" print(\"{0} - words = {1}\\n\".format(text2,countWords(text2)))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -437,11 +402,8 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.8.py\n",
- "#Counting Words in a Piece of Text\n",
"\n",
"\n",
- "#Function to read a piece of text\n",
"def readLine(line):\n",
" \n",
" line.pop()\n",
@@ -449,7 +411,6 @@
" #line.append(raw_input()+\" \")\n",
"\n",
"\n",
- "#Function to determine if a character is alphabetic\n",
"def alphabetic(c):\n",
" if ( (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z') ):\n",
" return True\n",
@@ -457,7 +418,6 @@
" return False\n",
"\n",
"\n",
- "#Function to count the number of words in a string\n",
"def countWords(string):\n",
" \n",
" #Variable Declaration\n",
@@ -494,7 +454,6 @@
" print(\"\\nThere are {0} words in the above text.\\n\".format(totalWords))\n",
"\n",
"\n",
- "#Top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -530,31 +489,25 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.9.py\n",
- "#Using the Dictionary Lookup Program\n",
"\n",
- "#Class Declaration\n",
"class entry:\n",
" def __init__(self,w,d):\n",
" self.word=w\n",
" self.definition=d\n",
"\n",
"\n",
- "#Function to check equality of two strings\n",
"def equalStrings(str1,str2):\n",
" if(str1==str2):\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
- "#Lookup function to return dictionary entry\n",
"def lookup(dictionary,search,entries):\n",
" for i in range(0,entries):\n",
" if ( equalStrings(search, dictionary[i].word) ):\n",
" return i;\n",
" return -1;\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" entries=10\n",
@@ -584,7 +537,6 @@
" print(\"Sorry, the word {0} is not in my dictionary.\\n\".format(word))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -614,17 +566,13 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.10.py\n",
- "#Modifying the Dictionary Lookup Using Binary Search\n",
"\n",
- "#Class Declaration\n",
"class entry:\n",
" def __init__(self,w,d): #Class constructor\n",
" self.word=w\n",
" self.definition=d\n",
"\n",
"\n",
- "#Function to compare two strings\n",
"def compareStrings(s1,s2):\n",
"\n",
" #Calculations\n",
@@ -639,7 +587,6 @@
"\n",
"\n",
"\n",
- "#Lookup function to return dictionary entry\n",
"def lookup(dictionary,search,entries):\n",
" \n",
" #Variable Declaration\n",
@@ -661,7 +608,6 @@
" return -1\n",
"\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #Variable Declaration\n",
@@ -691,7 +637,6 @@
" print(\"Sorry, the word {0} is not in my dictionary.\\n\".format(word))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],
@@ -721,16 +666,12 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "#10.11.py\n",
- "#Converting a String to its Integer Equivalent\n",
"\n",
"\n",
- "#Function to convert a string to an integer\n",
"def strToInt(string):\n",
" \n",
" return int(string)\n",
"\n",
- "#Main()\n",
"def main():\n",
"\n",
" #Result\n",
@@ -739,7 +680,6 @@
" print(\"{0}\\n\".format(strToInt(\"13\")))\n",
"\n",
"\n",
- "#Setting top level conditional script\n",
"if __name__=='__main__':\n",
" main()"
],