diff options
author | debashisdeb | 2014-06-20 15:42:42 +0530 |
---|---|---|
committer | debashisdeb | 2014-06-20 15:42:42 +0530 |
commit | 83c1bfceb1b681b4bb7253b47491be2d8b2014a1 (patch) | |
tree | f54eab21dd3d725d64a495fcd47c00d37abed004 /Programming_in_C | |
parent | a78126bbe4443e9526a64df9d8245c4af8843044 (diff) | |
download | Python-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.tar.gz Python-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.tar.bz2 Python-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.zip |
removing problem statements
Diffstat (limited to 'Programming_in_C')
-rw-r--r-- | Programming_in_C/Chapter_03.ipynb | 116 | ||||
-rw-r--r-- | Programming_in_C/Chapter_04.ipynb | 19 | ||||
-rw-r--r-- | Programming_in_C/Chapter_05.ipynb | 41 | ||||
-rw-r--r-- | Programming_in_C/Chapter_06.ipynb | 53 | ||||
-rw-r--r-- | Programming_in_C/Chapter_07.ipynb | 46 | ||||
-rw-r--r-- | Programming_in_C/Chapter_08.ipynb | 80 | ||||
-rw-r--r-- | Programming_in_C/Chapter_09.ipynb | 37 | ||||
-rw-r--r-- | Programming_in_C/Chapter_10.ipynb | 60 | ||||
-rw-r--r-- | Programming_in_C/Chapter_11.ipynb | 68 | ||||
-rw-r--r-- | Programming_in_C/Chapter_12.ipynb | 19 | ||||
-rw-r--r-- | Programming_in_C/Chapter_13.ipynb | 18 | ||||
-rw-r--r-- | Programming_in_C/Chapter_14.ipynb | 4 | ||||
-rw-r--r-- | Programming_in_C/Chapter_16.ipynb | 16 | ||||
-rw-r--r-- | Programming_in_C/Chapter_17.ipynb | 7 | ||||
-rw-r--r-- | Programming_in_C/Chapter_18.ipynb | 36 | ||||
-rw-r--r-- | Programming_in_C/Chapter_19.ipynb | 5 |
16 files changed, 96 insertions, 529 deletions
diff --git a/Programming_in_C/Chapter_03.ipynb b/Programming_in_C/Chapter_03.ipynb index 0f1f4347..bbc7d9cf 100644 --- a/Programming_in_C/Chapter_03.ipynb +++ b/Programming_in_C/Chapter_03.ipynb @@ -1,6 +1,7 @@ { "metadata": { - "name": "Chapter III" + "name": "", + "signature": "sha256:57f27b589000036417c51c927626e752909312f11d9fc5346eab037945b09afc" }, "nbformat": 3, "nbformat_minor": 0, @@ -11,25 +12,35 @@ "cell_type": "heading", "level": 1, "metadata": {}, - "source": "Chapter 3: Compiling and running your first program" + "source": [ + "Chapter 3: Compiling and running your first program" + ] }, { "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.1, Page number: 11" + "source": [ + "Program 3.1, Page number: 11" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.1.py\n#first Python Program\n\n#Print Statement\nprint(\"Programming is Fun.\")", + "input": [ + "\n", + "#Print Statement\n", + "print(\"Programming is Fun.\")" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "Programming is Fun.\n" + "text": [ + "Programming is Fun.\n" + ] } ], "prompt_number": 1 @@ -38,19 +49,30 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.2, Page number: 14" + "source": [ + "Program 3.2, Page number: 14" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.2.py\n#Writing Your First C Program(Version2)\n\n#Print statement\nprint(\"Programming is Fun.\")\nprint(\"And Programming in Python is even more fun\")", + "input": [ + "\n", + "\n", + "#Print statement\n", + "print(\"Programming is Fun.\")\n", + "print(\"And Programming in Python is even more fun\")" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "Programming is Fun.\nAnd Programming in Python is even more fun\n" + "text": [ + "Programming is Fun.\n", + "And Programming in Python is even more fun\n" + ] } ], "prompt_number": 2 @@ -59,19 +81,33 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.3, Page number: 14" + "source": [ + "Program 3.3, Page number: 14" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.3.py\n#Displaying multiple Lines of output\n\n#Print statements using escape sequence\nprint(\"Testing...\\n..1\\n...2\\n....3\\n\")", + "input": [ + "#3.3.py\n", + "#Displaying multiple Lines of output\n", + "\n", + "#Print statements using escape sequence\n", + "print(\"Testing...\\n..1\\n...2\\n....3\\n\")" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "Testing...\n..1\n...2\n....3\n\n" + "text": [ + "Testing...\n", + "..1\n", + "...2\n", + "....3\n", + "\n" + ] } ], "prompt_number": 3 @@ -80,19 +116,27 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.4, Page number: 15" + "source": [ + "Program 3.4, Page number: 15" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.4.py\n#Displaying Variables\n \nsum=50+25\nprint(\"The sum of 50 & 25 is: {0} \".format(sum))", + "input": [ + " \n", + "sum=50+25\n", + "print(\"The sum of 50 & 25 is: {0} \".format(sum))" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "The sum of 50 & 25 is: 75 \n" + "text": [ + "The sum of 50 & 25 is: 75 \n" + ] } ], "prompt_number": 4 @@ -101,19 +145,35 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.5, Page number: 16" + "source": [ + "Program 3.5, Page number: 16" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.5.py\n#Displayig multiple values\n\n#Variable declaration\nvalue1=50\nvalue2=25\n\n#Calculation\nsum=value1+value2\n\n#Result\nprint(\"The sum of {0} & {1} is: {2}\".format(value1,value2,sum))", + "input": [ + "\n", + "\n", + "#Variable declaration\n", + "value1=50\n", + "value2=25\n", + "\n", + "#Calculation\n", + "sum=value1+value2\n", + "\n", + "#Result\n", + "print(\"The sum of {0} & {1} is: {2}\".format(value1,value2,sum))" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "The sum of 50 & 25 is: 75\n" + "text": [ + "The sum of 50 & 25 is: 75\n" + ] } ], "prompt_number": 5 @@ -122,19 +182,35 @@ "cell_type": "heading", "level": 3, "metadata": {}, - "source": "Program 3.6, Page number: 17" + "source": [ + "Program 3.6, Page number: 17" + ] }, { "cell_type": "code", "collapsed": false, - "input": "#3.6.py\n#Using Comment in a program\n\n#'#(Hash/Pound)' is used to display a comment in python\n#This is a comment\n\n#Variable declarations\nvalue1=50\nvalue2=25\n\n#Calculation\nsum=value1+value2\n\n#Result\nprint(\"The sum of {0} & {1} is {2}\".format(value1,value2,sum))", + "input": [ + "\n", + "\n", + "#Variable declarations\n", + "value1=50\n", + "value2=25\n", + "\n", + "#Calculation\n", + "sum=value1+value2\n", + "\n", + "#Result\n", + "print(\"The sum of {0} & {1} is {2}\".format(value1,value2,sum))" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "The sum of 50 & 25 is 75\n" + "text": [ + "The sum of 50 & 25 is 75\n" + ] } ], "prompt_number": 6 diff --git a/Programming_in_C/Chapter_04.ipynb b/Programming_in_C/Chapter_04.ipynb index f7f7405b..43a3ac6c 100644 --- a/Programming_in_C/Chapter_04.ipynb +++ b/Programming_in_C/Chapter_04.ipynb @@ -27,17 +27,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#4.1.py\n", - "#Using the Basic Data Types\n", "\n", - "#Variable Declarations\n", "integerVar=100\n", "floatingVar=331.79\n", "doubleVar=8.44e+11\n", "charVar='w'\n", "boolVar=bool(0)\n", "\n", - "#Result\n", "print(\"integerVar={0}\".format(integerVar))\n", "print(\"floatingVar={0}\".format(floatingVar))\n", "print(\"doubleVar={0}\".format(doubleVar))\n", @@ -73,16 +69,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#4.2.py\n", - "#Using the Arithmetic Operators\n", "\n", - "#Variable declarations\n", "a=100\n", "b=2\n", "c=25\n", "d=4\n", "\n", - "#Calculations/Results\n", "result=a-b #subtraction\n", "print(\"a-b={0}\".format(result)) #result\n", "\n", @@ -126,16 +118,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#4.3.py\n", - "#More Examples with Arithmetic Operations\n", "\n", - "#Variable Declarations\n", "a=25\n", "b=2\n", "c=25.0\n", "d=2.0\n", "\n", - "#Calculations/Result\n", "print(\"6 + a / 5 * b = {0}\".format(6+a/5*b))\n", "print(\"a / b * b = {0}\".format(a/b*b))\n", "print(\"c / d * d = {0}\".format(c/d*d))\n", @@ -169,16 +157,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#4.4.py\n", - "#Illustrating the Modulus Operator\n", "\n", - "#Variable Declarations\n", "a=25\n", "b=5\n", "c=10\n", "d=7\n", "\n", - "#Calculations/Result\n", "print(\"a % b = {0}\".format(a%b))\n", "print(\"a % c = {0}\".format(a%c))\n", "print(\"a % d = {0}\".format(a%d))\n", @@ -212,10 +196,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#4.5.py\n", - "#Converting Between Integers and Floats\n", "\n", - "#Variable Declarations\n", "f1=123.125\n", "f2=1.0\n", "i1=1\n", diff --git a/Programming_in_C/Chapter_05.ipynb b/Programming_in_C/Chapter_05.ipynb index 90be6c84..588cb6d1 100644 --- a/Programming_in_C/Chapter_05.ipynb +++ b/Programming_in_C/Chapter_05.ipynb @@ -27,13 +27,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.1.py\n", - "#Calculating the Eighth Triangular Number\n", "\n", - "#Variable Declaration\n", "triangularNumber = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;\n", "\n", - "#Result\n", "print(\"The eighth triangular number is {0}\".format(triangularNumber))" ], "language": "python", @@ -61,17 +57,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.2.py\n", - "#Calculating the 200th Triangular Number\n", "\n", - "#Variable Declaration\n", "triangularNumber=0\n", "\n", - "#Calculation\n", "for i in range (201):\n", " triangularNumber=triangularNumber+i \n", "\n", - "#Result\n", "print(\"The 200th triangular number is {0}\".format(triangularNumber))" ], "language": "python", @@ -99,17 +90,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.3.py\n", - "#Generating a Table of Triangular Numbers\n", "\n", "print(\"TABLE OF TRIANGULAR NUMBERS\\n\\n\")\n", "print(\" n Sum from 1 to n\\n\")\n", "print(\"--- -----------------\\n\")\n", "\n", - "#Variable Declarations\n", "triangularNumber=0\n", "\n", - "#Calculation/Result\n", "for i in range (1,11):\n", " triangularNumber=triangularNumber+i\n", " print(\" {0} {1}\\n\".format(i,triangularNumber))" @@ -165,18 +152,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.4.py\n", - "#Asking the User for Input\n", "\n", - "#Variable Declaration/User Input\n", "triangularNumber=0\n", "number=10 #number=input(\"What triangular number do you want?\")\n", "\n", - "#Calculations\n", "for n in range (1,(number+1)):\n", " triangularNumber+=n\n", "\n", - "#Result\n", "print(\"triangular number {0} is {1}\".format(number,triangularNumber))" ], "language": "python", @@ -204,10 +186,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.5.py\n", - "#Using Nested for Loops\n", "\n", - "#Calculations\n", "for counter in range(1,6): #Outer Loop\n", " number=12 #input(\"what triangular number do you want? \")\n", "\n", @@ -248,13 +227,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.6.py\n", - "#Introducing the while Statement\n", "\n", - "#Variable Declaration\n", "count=1\n", "\n", - "#Calculation/Iteration `\n", "while (count<=5):\n", " print(\"{0}\\n\".format(count)) #Result\n", " count+=1" @@ -293,21 +268,16 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.7.py\n", - "#Finding the Greatest Common Divisor\n", "\n", "print(\"Please type in two nonnegative integers.\")\n", - "#Variable Declaration/User Input\n", "u=8 #u=input()\n", "v=14 #v=input()\n", "\n", - "#Calculation\n", "while(v!=0):\n", " temp=u%v\n", " u=v\n", " v=temp\n", "\n", - "#Result\n", "print(\"Their greatest common divisor is {0}\\n\".format(u))" ], "language": "python", @@ -337,16 +307,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.8.py\n", - "#Reversing the Digits of a Number\n", "\n", - "#Import Library\n", "import sys\n", "\n", - "#Variable declaration/User Input\n", "number=113 #number=input(\"Enter your number.\\n\")\n", "\n", - "#Calculation/Result\n", "while(number!=0):\n", " right_digit=number%10\n", " sys.stdout.write(\"{0}\".format(right_digit))\n", @@ -380,17 +345,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#5.9.py\n", - "#Implementing a Revised Program to Reverse the Digits of a Number\n", - "#(do-while equivalent code)\n", "\n", - "#Import Library\n", "import sys\n", "\n", - "#Variable Declaration/User Input\n", "number=428 #number=input(\"Enter your number:\\n\")\n", "\n", - "#Calculation/Result\n", "while True: #Enter loop instantly for the first time\n", " right_digit=number%10\n", " sys.stdout.write(\"{0}\".format(right_digit))\n", diff --git a/Programming_in_C/Chapter_06.ipynb b/Programming_in_C/Chapter_06.ipynb index a612ce70..ef1fef64 100644 --- a/Programming_in_C/Chapter_06.ipynb +++ b/Programming_in_C/Chapter_06.ipynb @@ -27,20 +27,15 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.1.py\n", - "#Calculating the Absolute Value of an Integer\n", "\n", - "#Variable Declaration/User input\n", "number=12 #number=int(raw_input(\"Type in your number: \"))\n", "\n", - "#Calculation\n", "try:\n", " if( number < 0 ):\n", " number=-number #change sign,if number is negative\n", "except: \n", " print \"not a number\" #Invalid input/value error\n", " \n", - "#Result\n", "print (\"The absolute Value is {0}\".format(number))" ], "language": "python", @@ -68,20 +63,14 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.2.py\n", - "#Calculating average & counting the number\n", - "#of failures from a set of grades\n", "\n", - "#Variable Declarations\n", "gradeTotal=0\n", "failureCount=0\n", "i=0\n", "\n", - "#User Input\n", "numberOfGrades=5 #numberOfGrades=int(raw_input(\"How many grades will you be entering? \"))\n", "grade=[72,83,91,89,95]\n", "\n", - "#Calculation\n", "while(i<numberOfGrades):\n", " gradeTotal=gradeTotal+grade[i]\n", " if(grade<65):\n", @@ -90,7 +79,6 @@ "\n", "average=float(gradeTotal/numberOfGrades)\n", " \n", - "#Result\n", "print(\"Grade average= {0:.2f}\".format(average))\n", "print(\"Number of failures= {0}\".format(failureCount))" ], @@ -120,16 +108,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.3.py\n", - "#Determining if a Number Is Even or Odd\n", "\n", - "#Variable declaration/User input\n", "number_to_test=30 #number_to_test=int(raw_input(\"Enter your number to be tested: \"))\n", "\n", - "#Calculation\n", "remainder=number_to_test%2\n", "\n", - "#Result\n", "if(remainder==0):\n", " print(\"The number is even\")\n", "if(remainder!=0):\n", @@ -160,16 +143,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.4.py\n", - "#Program to determine if a number is even or odd (Ver. 2)\n", "\n", - "#Variable declaration/User input\n", "number_to_test=45 #number_to_test=int(raw_input(\"Enter your Number to be tested: \"))\n", "\n", - "#Calculation\n", "remainder=number_to_test%2\n", "\n", - "#Result\n", "if(remainder==0):\n", " print(\"The number is even.\\n\")\n", "else: #using 'else' instead of second 'if'\n", @@ -201,18 +179,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.5.py\n", - "#Determining if a Year Is a Leap Year\n", "\n", - "#Variable declaration/User input\n", "year=1900 #year=int(raw_input(\"Enter the year to be tested: \"))\n", "\n", - "#Calculations\n", "rem_4=year%4\n", "rem_100=year%100\n", "rem_400=year%400\n", "\n", - "#Result\n", "if((rem_4==0 and rem_100!=0)or rem_400==0):\n", " print(\"It's a leap year.\")\n", "else:\n", @@ -244,13 +217,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.6.py\n", - "#Implementing the Sign Function\n", "\n", - "#Variable declaration/User input\n", "number=450 #number=int(raw_input(\"Please type in a number: \"))\n", "\n", - "#Calculations\n", "try:\n", " if(number<0): #Negative Number\n", " sign=-1\n", @@ -261,7 +230,6 @@ "except: #Value error\n", " print(\"invalid input\")\n", "\n", - "#Result\n", "print(\"Sign= {0}\".format(sign))" ], "language": "python", @@ -289,13 +257,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.7.py\n", - "#Implementing the Sign Function\n", "\n", - "#variable declaration/User input\n", "ch='z' #ch=raw_input(\"Enter a single character: \")\n", "\n", - "#Calculation/Result\n", "if((ch>='a' and ch <='z') or (ch>='A' and ch<='Z')):\n", " print(\"It's an alphabetic character.\")\n", "elif(ch>='0'and ch<='9'):\n", @@ -328,13 +292,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.8.py\n", - "#evaluate simple expressions of the form\n", - "#<number operator number>\n", "\n", "\n", "try:\n", - "#Variable declaration/User input\n", " print(\"Type in your expression(with spaces inbetween): \")\n", " value1, operator, value2=\"5 + 2\".split()\n", " #value1, operator, value2=raw_input().split()\n", @@ -343,10 +303,8 @@ " print(\"err.. follow the syntax <value operator value>\") \n", " print(\"with spaces inbetween\\n\")\n", "\n", - "#Parsing\n", "value1,value2=[float(value1),float(value2)]\n", "\n", - "#Calculation/Result\n", "if(operator=='+'):\n", " print(\"answer: {0:.2f}\".format(value1+value2))\n", "elif(operator=='-'):\n", @@ -382,13 +340,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.9.py\n", - "#evaluate simple expressions of the form\n", - "#<number operator number> (Version 2)\n", "\n", "\n", "try:\n", - "#Variable declaration/User input\n", " print(\"Type in your expression(with spaces inbetween): \")\n", " value1, operator, value2=\"3 * 5\".split()\n", " #value1, operator, value2=raw_input().split()\n", @@ -398,10 +352,8 @@ " print(\"err.. follow the syntax <value operator value>\") \n", " print(\"with spaces inbetween\\n\")\n", "\n", - "#parsing\n", "value1,value2=[float(value1), float(value2)]\n", "\n", - "#Calculation/Result\n", "if(operator=='+'):\n", " print(\"Answer= {0:.2f}\".format(value1+value2))\n", "elif(operator=='-'):\n", @@ -442,13 +394,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#6.10.py\n", - "#Generating a Table of Prime Numbers\n", "\n", - "#Variable declarations\n", "p=2\n", "\n", - "#Calculations\n", "while(p<=50): #Outer loop\n", " isPrime=1 #Variable declaration\n", " d=2 \n", @@ -458,7 +406,6 @@ " d=d+1 #End of inner loop\n", " \n", " if( isPrime!=0):\n", - "#Print Result\n", " print \" \",p \n", " p=p+1 #End of outer loop" ], diff --git a/Programming_in_C/Chapter_07.ipynb b/Programming_in_C/Chapter_07.ipynb index de714e04..7c0f6329 100644 --- a/Programming_in_C/Chapter_07.ipynb +++ b/Programming_in_C/Chapter_07.ipynb @@ -27,13 +27,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.1.py\n", - "#Working with an Array(or list in python)\n", "\n", - "#Variable/List declaration\n", "values=[0]*10\n", "\n", - "#Initialisation/Calculation\n", "values[0]=197\n", "values[2]=-100\n", "values[5]=350\n", @@ -42,7 +38,6 @@ "values[2]-=1\n", "i=0\n", "\n", - "#Iteration/Result\n", "for index in values:\n", " print(\"values[{0}] = {1}\".format(i,index))\n", " i=i+1" @@ -81,20 +76,14 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.2.py\n", - "#Demonstrating an Array of Counters\n", "\n", - "#variable/List Declaration\n", "ratingCounters=[0]*11\n", "\n", - "#Loop-1\n", "for i in range(1,11):\n", " ratingCounters[i]=0\n", "\n", "print(\"Enter your Responses:\")\n", "\n", - "#Loop-2\n", - "#Clculation\n", "for i in range (1,21):\n", " response=5 #score=5 for all iterations\n", " #response=input()\n", @@ -104,11 +93,9 @@ " else:\n", " ratingCounters[response]+=1\n", "\n", - "#Result\n", "print(\"\\n\\n Rating | Number of Responses\\n\")\n", "print(\" ----- -------------------\")\n", "\n", - "#Loop-3\n", "for i in range(1,11):\n", " print(\" {0} {1}\".format(i,ratingCounters[i]))" ], @@ -152,20 +139,15 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.3.py\n", - "#Generating Fibonacci Numbers\n", "\n", - "#Variable/List Declaration\n", "Fibonacci=[0]*15\n", "\n", "Fibonacci[0]=0\n", "Fibonacci[1]=1\n", "\n", - "#Loop-1\n", "for i in range(2,15):\n", " Fibonacci[i]=Fibonacci[i-2]+Fibonacci[i-1] #Calculation\n", "\n", - "#Loop-2\n", "for i in range(15):\n", " print(\"{0}\".format(Fibonacci[i])) #Print Result" ], @@ -208,10 +190,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.4.py\n", - "#Revising the Program to Generate Prime Numbers,Version 2\n", "\n", - "#Variable Declaration\n", "primeIndex=2\n", "primes=[0]*50\n", "\n", @@ -219,7 +198,6 @@ "primes[1]=3\n", "p=5\n", "\n", - "#Calculations\n", "while(p<=50): #Outer Loop-1\n", " isPrime=True\n", " \n", @@ -235,7 +213,6 @@ " primeIndex+=1\n", " p=p+2\n", "\n", - "#Results\n", "for i in range (primeIndex): #Outer Loop-2\n", " print(\"{0}\".format(primes[i]))" ], @@ -278,18 +255,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.5.py\n", - "#Initializing Arrays\n", "\n", - "#Variable/List Declarations\n", "array_values=[0]*10\n", "array_values[0:4]=[0,1,4,9,16]\n", "\n", - "#Calculations\n", "for i in range(5,10):\n", " array_values[i]=i*i\n", "\n", - "#Results\n", "for i in range(10):\n", " print(\"array values[{0}] = {1}\".format(i,array_values[i]))" ], @@ -327,16 +299,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.6.py\n", - "#Introducing Character Arrays\n", "\n", - "#Import Library\n", "import sys #For sys.stdout.write()\n", "\n", - "#Variable/List Declaration\n", "word=['H','e','l','l','o','!']\n", "\n", - "#Iterator/Result\n", "for i in word:\n", " sys.stdout.write(\"{0} \".format(i))\n", "print(\"\\n\")" @@ -367,13 +334,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.7.py\n", - "#Converting a Positive Integer to Another Base\n", "\n", - "#import Library\n", "import sys #for sys.stdout.write()\n", "\n", - "#Variable Declarations\n", "baseDigits=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']\n", "convertedNumber=[0]*10\n", "index=0\n", @@ -381,7 +344,6 @@ "numberToConvert=234 #numberToConvert=input(\"Number to be converted?: \")\n", "base=2 #base=input(\"Base?: \")\n", "\n", - "#Calculations\n", "while True:\n", " convertedNumber[index]=numberToConvert%base\n", " index+=1\n", @@ -389,7 +351,6 @@ " if(numberToConvert==0):\n", " break\n", "\n", - "#Result\n", "print(\"Converted Number= \")\n", "index-=1\n", "while(index>=0):\n", @@ -426,29 +387,22 @@ "cell_type": "code", "collapsed": false, "input": [ - "#7.8.py\n", - "#Generating Fibonacci Numbers Using Variable-Length Arrays\n", "\n", - "#import Libraries\n", "import sys #For sys.exit() \n", " \n", - "#User Input \n", "numFibs=18 #numFibs=input(\"How many Fibonacci numbers do you want (between 1 and 75)? \")\n", "\n", "if(numFibs<1 or numFibs>75):\n", " print(\"bad number,sorry!\")\n", " sys.exit()\n", "\n", - "#Variable Declarations \n", "Fibonacci=[0]*numFibs\n", "Fibonacci[0]=0\n", "Fibonacci[1]=1\n", "\n", - "#Calculation\n", "for i in range(2,numFibs):\n", " Fibonacci[i]=Fibonacci[i-2]+Fibonacci[i-1] \n", " \n", - "#Result\n", "for i in range(numFibs):\n", " print(\"{0}\".format(Fibonacci[i]))" ], diff --git a/Programming_in_C/Chapter_08.ipynb b/Programming_in_C/Chapter_08.ipynb index a4113d97..f8d5211b 100644 --- a/Programming_in_C/Chapter_08.ipynb +++ b/Programming_in_C/Chapter_08.ipynb @@ -27,8 +27,6 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.1.py\n", - "#Writing a Function in python\n", "\n", "\n", "def printMessage(): #Function to Print Message\n", @@ -68,8 +66,6 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.2.py\n", - "#Calling Functions\n", "\n", "\n", "def printMessage(): #Function to Print Message\n", @@ -111,8 +107,6 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.3.py\n", - "#More on Calling Functions\n", "\n", "\n", "def printMessage(): #Function to Print Message\n", @@ -161,8 +155,6 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.4.py\n", - "#Calculating the nth Triangular Number\n", "\n", "\n", "def calculateTriangularNumber(n): #Function to calculate triangular number\n", @@ -210,10 +202,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.5.py\n", - "#Revising the Program to Find the Greatest Common Divisor\n", "\n", - "#Import Library \n", "import sys \n", "\n", "def gcd(u,v): #Function to calculate gcd\n", @@ -261,10 +250,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.6.py\n", - "#Finding the Greatest Common Divisor and Returning the Results\n", "\n", - "#Import Library \n", "import sys \n", "\n", "def gcd(u,v): #Function to calculate gcd\n", @@ -313,12 +299,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.7.py\n", - "#Calculating the Absolute Value\n", "\n", - "#yourstory.in\n", "\n", - "#Calculations\n", "def absoluteValue(x): #Function to calculate & return absolute values\n", " if(x<0):\n", " x=-x\n", @@ -330,7 +312,6 @@ " f2=20.0\n", " f3=-5.0\n", " il=-716\n", - "#Result \n", " result=absoluteValue(f1)\n", " print(\"result= {0:.2f}\".format(result))\n", " print(\"f1={0:.2f}\".format(f1))\n", @@ -347,7 +328,6 @@ " print(\"{0:.2f}\".format(absoluteValue((-6.0)/4)))\n", "\n", "\n", - "#End of Main()\n", " \n", "if __name__=='__main__': #Setting Top level conditional script\n", " main()" @@ -382,17 +362,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.8.py\n", - "#Calculating the Square Root of a Number using Newton-Raphson Method \n", "\n", "\n", - "#Function to return absolute value\n", "def absoluteValue(x): \n", " if(x<0):\n", " x=-x\n", " return x\n", "\n", - "#function to calculate square root\n", "def squareRoot(x):\n", " epsilon=0.0001\n", " guess=1.0\n", @@ -400,13 +376,11 @@ " guess=(x/guess+guess)/2.0\n", " return guess\n", "\n", - "#Main()\n", "def main():\n", " print(\"squareRoot (2.0) = {0}\".format(squareRoot (2.0)));\n", " print(\"squareRoot (144.0) = {0}\".format(squareRoot (144.0)));\n", " print(\"squareRoot (17.5) = {0}\".format(squareRoot (17.5)));\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -437,10 +411,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.9.py\n", - "#Finding the Minimum Value in an Array\n", "\n", - "#Function to return minimum value\n", "def minimum(values):\n", " minValue=values[0] #Variable Declaration\n", " for i in range (1,10): #Calculation\n", @@ -449,7 +420,6 @@ "\n", " return minValue\n", " \n", - "#Main()\n", "def main():\n", " scores=[] #Variable Declaration\n", " print(\"Enter 10 scores:\")\n", @@ -460,7 +430,6 @@ " minScore=minimum(scores) #Function call & assignment\n", " print(\"\\nMinimum score is {0}\\n\".format(minScore)) #Result\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -492,10 +461,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.10.py\n", - "#Revising the Function to Find the Minimum Value in an Array\n", "\n", - "#Function to return minimum value\n", "def minimum(values,numberOfElements): \n", " minValue=values[0] #Variable Declaration\n", " for i in range(1,numberOfElements): #Iteration/Calculations\n", @@ -504,7 +470,6 @@ " \n", " return minValue\n", "\n", - "#Main()\n", "def main():\n", " #List/Variable Delcaration\n", " array1 = [ 157, -28, -37, 26, 10 ] \n", @@ -514,7 +479,6 @@ " print(\"array1 minimum: {0}\".format(minimum (array1, 5)));\n", " print(\"array2 minimum: {0}\".format(minimum (array2, 7)));\n", "\n", - "#Setting top level conditional script \n", "if __name__=='__main__':\n", " main()" ], @@ -544,18 +508,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.11.py\n", - "#Changing Array Elements in Functions\n", "\n", - "#Import System Library\n", "import sys\n", "\n", - "#Function to multiply elements by 2\n", "def multiplyBy2(array,n):\n", " for i in range (0,n): #Iteration/Calculation\n", " array[i]*=2\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List/Variable Declaration\n", @@ -566,7 +525,6 @@ " sys.stdout.write(\"{0:.2f} \".format(floatVals[i])) #Result\n", " print(\"\\n\")\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -596,13 +554,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.12.py\n", - "#\n", "\n", - "#Import system Library \n", "import sys\n", "\n", - "#Function to sort the array\n", "def sort(a,n):\n", "\n", " for i in range (0,n-1): #Calculations\n", @@ -612,7 +566,6 @@ " a[i]=a[j]\n", " a[j]=temp\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List/Variable Declaration \n", @@ -631,7 +584,6 @@ " print(\"\\n\")\n", "\n", "\n", - "#Setting top level conditional script \n", "if __name__=='__main__':\n", " main()" ], @@ -668,13 +620,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.13.py\n", - "#Using Multidimensional Arrays and Functions\n", "\n", - "#Import system Library\n", "import sys\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List/Variable Declaration\n", @@ -696,14 +644,12 @@ " displayMatrix(sampleMatrix) #Function call-5\n", "\n", "\n", - "#Function to multiply matrix by a scalar quantity \n", "def scalarMultiply(matrix,scalar):\n", " for row in range(0,3): #Calculation\n", " for column in range(0,5):\n", " matrix[row][column]*=scalar \n", "\n", "\n", - "#Function to display the matrix\n", "def displayMatrix(matrix):\n", " for row in range(0,3): #Result\n", " for column in range(0,5):\n", @@ -711,7 +657,6 @@ " sys.stdout.write(\"\\n\")\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -756,13 +701,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.13A.py\n", - "#Multidimensional Variable-Length Arrays\n", "\n", - "#Import system Library\n", "import sys\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List/Variable Declaration\n", @@ -784,14 +725,12 @@ " displayMatrix(3,5,sampleMatrix) #Function call-5\n", "\n", "\n", - "#Function to multiply matrix by a scalar quantity \n", "def scalarMultiply(nRows,nCols,matrix,scalar):\n", " for row in range(0,nRows): #Calculation\n", " for column in range(0,nCols):\n", " matrix[row][column]*=scalar \n", "\n", "\n", - "#Function to display the matrix\n", "def displayMatrix(nRows,nCols,matrix):\n", " for row in range(0,nRows): #Result\n", " for column in range(0,nCols):\n", @@ -799,7 +738,6 @@ " sys.stdout.write(\"\\n\")\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -844,13 +782,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.14.py\n", - "#Converting a Positive Integer to Another Base\n", "\n", - "#Import system Libraries\n", "import sys\n", "\n", - "#Function to get Number & Base\n", "def getNumberAndBase():\n", " \n", " #Global Reference\n", @@ -866,7 +800,6 @@ " print(\"Bad base - must be between 2 and 16\\n\");\n", " base = 10;\n", "\n", - "#Conversion Function\n", "def convertNumber():\n", " \n", " #Global Reference\n", @@ -882,7 +815,6 @@ " numberToConvert/=base\n", "\n", "\n", - "#Function to display\n", "def displayConvertedNumber():\n", "\n", " #Global reference \n", @@ -904,14 +836,12 @@ "\n", "\n", "\n", - "#Main()\n", "def main():\n", " getNumberAndBase() #Function call-1\n", " convertNumber() #Function call-2\n", " displayConvertedNumber() #Function call-3\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -940,11 +870,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.15.py\n", - "#Illustrating Static and Automatic Variables\n", "\n", "\n", - "#Function to display variables\n", "def auto_static():\n", " global staticVar #Global reference\n", " autoVar=1 #variable Declaration\n", @@ -954,14 +881,12 @@ " autoVar+=1\n", " staticVar+=1\n", "\n", - "#Main()\n", "def main():\n", " global staticVar\n", " staticVar=1 #Variable Declaration\n", " for i in range(0,5):\n", " auto_static()\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -999,10 +924,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#8.16.py\n", - "#Calculating Factorials Recursively\n", "\n", - "#Function to calculate factorial\n", "def factorial(n):\n", " if( n == 0 ): #Calculation\n", " result = 1\n", @@ -1010,13 +932,11 @@ " result = n * factorial (n - 1)\n", " return result;\n", "\n", - "#Main()\n", "def main():\n", " for j in range (0,11):\n", " print(\"{0:3}! = {1}\\n\".format(j,factorial (j)))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], diff --git a/Programming_in_C/Chapter_09.ipynb b/Programming_in_C/Chapter_09.ipynb index 684317a5..56b0b95f 100644 --- a/Programming_in_C/Chapter_09.ipynb +++ b/Programming_in_C/Chapter_09.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.1.py\n", - "#Illustrating a Structure/Class in python\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Class Declaration\n", @@ -55,7 +52,6 @@ " print(\"Today's date is {0}/{1}/{2}\".format(today.month,today.day,today.year%100));\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -84,10 +80,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.2.py\n", - "#Determining Tomorrows Date\n", "\n", - "#Main()\n", "def main():\n", " #Class Declaration\n", " class date:\n", @@ -125,7 +118,6 @@ " print(\"Tomorrow's date is {0}/{1}/{2}\\n\".format(tomorrow.month,tomorrow.day,tomorrow.year));\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -156,10 +148,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.3.py\n", - "#Revising the Program to Determine Tomorrow's Date\n", "\n", - "#Class Declaration\n", "class date:\n", " def __init__(self): #Class Constructor\n", " #Default values\n", @@ -168,7 +157,6 @@ " year=0\n", " \n", "\n", - "#Main()\n", "def main():\n", " #creating instances\n", " today=date()\n", @@ -196,7 +184,6 @@ " print(\"Tomorrow's date is {0}/{1}/{2}\\n\".format(tomorrow.month,tomorrow.day,tomorrow.year));\n", "\n", "\n", - "#Function to find the number of days in a month \n", "def numberOfDays(d):\n", " \n", " #List Declaration\n", @@ -209,7 +196,6 @@ " return days\n", "\n", "\n", - "#Function to determine if it's a leap year\n", "def isLeapYear(d):\n", " if ( (d.year % 4 == 0 and d.year % 100 != 0) or d.year % 400 == 0 ):\n", " leapYearFlag = True # Its a leap year\n", @@ -220,7 +206,6 @@ "\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -251,10 +236,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.4.py\n", - "#Revising the Program to Determine Tomorrow's Date--Version 2\n", "\n", - "#Class Declaration\n", "class date:\n", " def __init__(self): #Class Constructor\n", " #Default values\n", @@ -282,7 +264,6 @@ "\n", "\n", "\n", - "#Main()\n", "def main():\n", " #creating instances\n", " thisDay=date()\n", @@ -299,7 +280,6 @@ "\n", "\n", "\n", - "#Function to find the number of days in a month \n", "def numberOfDays(d):\n", " \n", " #List Declaration\n", @@ -313,7 +293,6 @@ "\n", "\n", "\n", - "#Function to determine if it's a leap year\n", "def isLeapYear(d):\n", " if ( (d.year % 4 == 0 and d.year % 100 != 0) or d.year % 400 == 0 ):\n", " leapYearFlag = True # Its a leap year\n", @@ -324,7 +303,6 @@ "\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -355,10 +333,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.5.py\n", - "#Updating the Time by One Second\n", "\n", - "#Class Declaration\n", "class time:\n", " def __init__(self):\n", " hour=0\n", @@ -379,7 +354,6 @@ "\n", " return now\n", "\n", - "#Main()\n", "def main():\n", " #Creating instances\n", " currentTime=time()\n", @@ -396,7 +370,6 @@ "\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -427,13 +400,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.6.py\n", - "#Illustrating Arrays of Structures\n", "\n", - "#Import sys Library\n", "import sys\n", "\n", - "#Class Declaration\n", "class time:\n", " def __init__(self,h,m,s):\n", " #Variable Declarations\n", @@ -455,7 +424,6 @@ "\n", " return now\n", "\n", - "#Main()\n", "def main():\n", " #Creating instances\n", " testTimes = []\n", @@ -477,7 +445,6 @@ "\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -510,11 +477,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "#9.7.py\n", - "#Illustrating Structures and Arrays\n", "\n", "\n", - "#Main()\n", "def main():\n", " #Class Declaration\n", " class month:\n", @@ -545,7 +509,6 @@ " print(\"{0}{1}{2} {3}\\n\".format(months[i].name[0],months[i].name[1],months[i].name[2], months[i].numberOfDays))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], 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()" ], diff --git a/Programming_in_C/Chapter_11.ipynb b/Programming_in_C/Chapter_11.ipynb index a010bcdb..76ced362 100644 --- a/Programming_in_C/Chapter_11.ipynb +++ b/Programming_in_C/Chapter_11.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.1.py\n", - "#Illustrating Pointers\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -42,7 +39,6 @@ " #Result\n", " print(\"count={0} , x={1}\".format(count,x))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -71,10 +67,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.2.py\n", - "#More Pointer Basics\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -92,7 +85,6 @@ "\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -123,10 +115,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.3\n", - "#Using Pointers in Expressions\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -138,7 +127,6 @@ " #Result\n", " print(\"i1 = {0}, i2 = {1}, p1 = {2}, p2 = {3}\\n\".format(i1, i2, p1, p2))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -168,10 +156,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.4.py\n", - "#Using Pointers to classes\n", "\n", - "#Main()\n", "def main():\n", " class date:\n", " def __init__(self): #Class constructor\n", @@ -190,7 +175,6 @@ " #Result\n", " print(\"Today's date is {0}/{1}/{2}\".format(datePtr.month, datePtr.day, datePtr.year))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -219,10 +203,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.5.py\n", - "#Using classes Containing pointer variables\n", "\n", - "#Main()\n", "def main():\n", " class intPtrs:\n", " def __init__(self): #Class constructor\n", @@ -241,7 +222,6 @@ " print(\"i2 = {0}, pointers.p2 = {1}\\n\".format(i2, pointers.p2))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -273,11 +253,8 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.6.py\n", - "#Using Linked Lists\n", "\n", "\n", - "#Main()\n", "def main():\n", " class entry:\n", " def __init(self): #Class constructor\n", @@ -303,7 +280,6 @@ "\n", "\n", "\n", - "#setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -333,10 +309,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.7.py\n", - "#Traversing a linked list\n", "\n", - "#Main()\n", "def main():\n", " class entry:\n", " def __init__(self): #Class constructor\n", @@ -362,7 +335,6 @@ " list_pointer = list_pointer.nxt;\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -396,15 +368,11 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.8.py\n", - "#Using Pointers and Functions\n", "\n", - "#Function to change incoming varible\n", "def test(int_pointer):\n", " int_pointer=100\n", " return int_pointer\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable declaration\n", @@ -417,7 +385,6 @@ " print(\"After the call to test i = {0}\".format(p))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -447,10 +414,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.9.py\n", - "#Using Pointers to Exchange Values\n", "\n", - "#Function to exchange & return values\n", "def exchange(pint1,pint2):\n", " temp=pint1\n", " pint1=pint2\n", @@ -458,7 +422,6 @@ " return pint1,pint2\n", "\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -478,7 +441,6 @@ " print(\"i1 ={0}, i2 ={1}\\n\".format(i1, i2))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -512,10 +474,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.10.py\n", - "#Returning a Pointer from a Function\n", "\n", - "#Class Declaration\n", "class entry:\n", " def __init__(self): #Class constructor\n", " self.value=0\n", @@ -532,7 +491,6 @@ "\n", " return 0\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Creating instance\n", @@ -562,7 +520,6 @@ " print(\"Not found.\\n\")\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -593,10 +550,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.11.py\n", - "#Working with Pointers to Arrays/Lists\n", "\n", - "#Function to evaluate sum of array elements\n", "def arraySum (array,n):\n", "\n", " #Variable Declaration\n", @@ -607,7 +561,6 @@ " sum += array[i]\n", " return sum\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List Declaration\n", @@ -615,7 +568,6 @@ " #Result\n", " print(\"The sum is {0}\\n\".format(arraySum (values, 10)))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -645,10 +597,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.12.py\n", - "#Summing the Elements of an Array--version 2\n", "\n", - "#Function to evaluate sum of array elements\n", "def arraySum (array,n):\n", " #Variable Declaration\n", " sum = 0 \n", @@ -657,7 +606,6 @@ " sum += i\n", " return sum\n", "\n", - "#Main()\n", "def main():\n", "\n", " #List Declaration\n", @@ -665,7 +613,6 @@ " #Result\n", " print(\"The sum is {0}\\n\".format(arraySum(values,10)))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -695,16 +642,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.13.py\n", - "#Version of copyString\n", "\n", - "#Function to copy string from source to destinaton\n", "def copyString(to, frm):\n", " global string2\n", " to=frm\n", " string2=to\n", "\n", - "#Main()\n", "def main():\n", " \n", " global string2\n", @@ -717,7 +660,6 @@ " copyString (string2, \"So is this.\") #Function call\n", " print(\"{0}\\n\".format(string2))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -749,16 +691,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.14.py\n", - "#Revised version of copyString\n", "\n", - "#Function to copy string from source to destinaton\n", "def copyString(to, frm):\n", " global string2\n", " to=frm\n", " string2=to\n", "\n", - "#Main()\n", "def main():\n", " \n", " global string2\n", @@ -771,7 +709,6 @@ " copyString (string2, \"So is this.\") #Function call\n", " print(\"{0}\\n\".format(string2))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -803,20 +740,15 @@ "cell_type": "code", "collapsed": false, "input": [ - "#11.15.PY\n", - "#Find the Length of a String\n", "\n", - "#Function to return string length\n", "def stringLength(string):\n", " return len(string) #Calculation\n", "\n", - "#Main()\n", "def main():\n", " print(\"{0} \".format(stringLength (\"stringLength test\")))\n", " print(\"{0} \".format(stringLength (\"\")))\n", " print(\"{0}\".format(stringLength (\"complete\")))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], diff --git a/Programming_in_C/Chapter_12.ipynb b/Programming_in_C/Chapter_12.ipynb index 7f498638..a19ac40d 100644 --- a/Programming_in_C/Chapter_12.ipynb +++ b/Programming_in_C/Chapter_12.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#12.1.py\n", - "#The bitwise AND operator\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -44,7 +41,6 @@ " print(word1&word2&word3)\n", " print(word1&1)\n", "\n", - "#Setting top level conditioanl script\n", "if __name__=='__main__':\n", " main()" ], @@ -76,10 +72,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#12.2.py\n", - "#Illustrate Bitwise Opertors\n", "\n", - "#Main()\n", "def main():\n", "\n", " #variable Declarations\n", @@ -100,7 +93,6 @@ " print(\"w1={0:3} w2={1:3}\".format(w1,w2))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -134,10 +126,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#12.3.py\n", - "#Implementing a Shift Function\n", "\n", - "#Function to perform bitwise shift\n", "def shift(value,n):\n", " if(n>0):\n", " value <<=n #Left shift\n", @@ -146,7 +135,6 @@ "\n", " return value\n", "\n", - "#Main()\n", "def main():\n", " #Variable Declaration\n", " w1=177777\n", @@ -158,7 +146,6 @@ " print(\"{0:7} {1:7}\".format(shift(w2,0),w2>>0))\n", " print(\"{0:7} \".format(shift(shift(w1,-3),3)))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -190,10 +177,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#12.4.py\n", - "#Implementing a Rotate Function\n", "\n", - "#Function to perform rotation\n", "def rotate(value,n):\n", "\n", " #Calculation\n", @@ -215,9 +199,7 @@ " return result\n", "\n", "\n", - "#Main()\n", "def main():\n", - "#Variable Declaration\n", " w1=0xabcdef00\n", " w2=0xffff1122\n", "\n", @@ -229,7 +211,6 @@ " print(\"%x\"%rotate(w1,44))\n", " \n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], diff --git a/Programming_in_C/Chapter_13.ipynb b/Programming_in_C/Chapter_13.ipynb index 0ccf61c4..6d75e6fa 100644 --- a/Programming_in_C/Chapter_13.ipynb +++ b/Programming_in_C/Chapter_13.ipynb @@ -27,17 +27,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#13.1.py\n", - "#defining constants\n", "\n", - "#Variable Decarations\n", "global YES\n", "global NO\n", "YES=1\n", "NO=0\n", "\n", "\n", - "#Function to check if a number is even or odd\n", "def isEven(number):\n", " global YES\n", " global NO\n", @@ -49,7 +45,6 @@ "\n", " return answer\n", "\n", - "#Main()\n", "def main():\n", " global YES\n", " global NO\n", @@ -67,7 +62,6 @@ " print(\"NO\")\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -97,36 +91,29 @@ "cell_type": "code", "collapsed": false, "input": [ - "#13.2.py\n", - "#Working more with constants\n", "\n", "global PI\n", "PI= 3.141592654\n", "\n", "\n", - "#Function to calculate area\n", "def area(r):\n", " global PI\n", " return (PI*r*r)\n", "\n", - "#Function to calculate circumference\n", "def circumference(r):\n", " global PI\n", " return (2*PI*r)\n", "\n", - "#Function to calculate volume\n", "def volume(r):\n", " global PI\n", " return (1.33 * PI*r*r*r)\n", " \n", "\n", - "#Main()\n", "def main():\n", " print(\"radius=1 {0:5} {1:5} {2:5}\".format(area(1),circumference(1),volume(1)))\n", " print(\"radius=4.98 {0:5} {1:5} {2:5}\".format(area(4.98),circumference(4.98),volume(4.98)))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], @@ -156,14 +143,10 @@ "cell_type": "code", "collapsed": false, "input": [ - "#13.3.py\n", - "#Defining global constants--advance\n", "\n", - "#Variable Declaration\n", "global QUARTS_PER_LITER\n", "QUARTS_PER_LITER=1.05687\n", "\n", - "#Main()\n", "def main():\n", " global QUARTS_PER_LITER #Global Reference\n", "\n", @@ -175,7 +158,6 @@ "\n", " print(\"{0} Liters = {1} gallons\".format(liters,gallons))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], diff --git a/Programming_in_C/Chapter_14.ipynb b/Programming_in_C/Chapter_14.ipynb index 4b34f1d0..d67dd4c7 100644 --- a/Programming_in_C/Chapter_14.ipynb +++ b/Programming_in_C/Chapter_14.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#14.1.py\n", - "#Using Enumerated Data Type\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Declaring an Enumerator \n", @@ -67,7 +64,6 @@ " print(\"...or 29 if it's a leap year\")\n", "\n", "\n", - "#Top level conditional script\n", "if __name__=='__main__':\n", " main()" ], diff --git a/Programming_in_C/Chapter_16.ipynb b/Programming_in_C/Chapter_16.ipynb index f6d06ea2..2b519af8 100644 --- a/Programming_in_C/Chapter_16.ipynb +++ b/Programming_in_C/Chapter_16.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#16.1.py\n", - "#Illustrating print function\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -89,7 +86,6 @@ " print(\"c1 = %i, c2 = %i\\n\"%(4, 12))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -155,13 +151,9 @@ "cell_type": "code", "collapsed": false, "input": [ - "#16.2.py\n", - "#Copying Characters from Standard Input to Standard Output\n", "\n", - "#Import system library\n", "import sys\n", "\n", - "#Main()\n", "def main():\n", " \n", " while (True):\n", @@ -174,7 +166,6 @@ " sys.exit()\n", " \n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -220,10 +211,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#16.3.py\n", - "#Program to copy one file to another\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration/ User Input\n", @@ -236,14 +224,12 @@ " #outName=raw_input()\n", "\n", " \n", - "#Try to open a file for reading\n", " try:\n", " inn=open(inName,\"r\") \n", " except:# Exception:\n", " print(\"cant open {0} for reading\".format(inName))\n", " sys.exit()\n", "\n", - "#try to open a file for writing\n", " try:\n", " out=open(outName,\"w\") \n", " except:# Exception:\n", @@ -253,13 +239,11 @@ " string=inn.read() #Read content from File-1\n", " out.write(string) #Write content to File-2\n", "\n", - "#Close Files\n", " inn.close()\n", " out.close()\n", "\n", " print(\"File has been copied.\\n\");\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" diff --git a/Programming_in_C/Chapter_17.ipynb b/Programming_in_C/Chapter_17.ipynb index 192aef85..c854a59b 100644 --- a/Programming_in_C/Chapter_17.ipynb +++ b/Programming_in_C/Chapter_17.ipynb @@ -27,10 +27,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#17.1.py\n", - "#File Copy Program Using Command-Line Arguments\n", "\n", - "#Import Libraries\n", "import sys\n", "\n", "def main():\n", @@ -40,7 +37,6 @@ " #print(\"need two file names!\")\n", " #sys.exit()\n", " \n", - "#Read Command Line Arguments\n", " inName=\"source.txt\" #str(sys.argv[1])\n", " outName=\"target.txt\" #str(sys.argv[2])\n", "\n", @@ -51,7 +47,6 @@ " print(\"cant open {0} for reading\".format(inName))\n", " sys.exit()\n", "\n", - "#try to open a file for writing\n", " try:\n", " out=open(outName,\"w\") \n", " except:# Exception:\n", @@ -61,7 +56,6 @@ " string=inn.read() #Read content from File-1\n", " out.write(string) #Write content to File-2\n", "\n", - "#Close Files\n", " inn.close()\n", " out.close()\n", "\n", @@ -69,7 +63,6 @@ " print(\"File has been copied.\\n\");\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" diff --git a/Programming_in_C/Chapter_18.ipynb b/Programming_in_C/Chapter_18.ipynb index 675ba691..86358365 100644 --- a/Programming_in_C/Chapter_18.ipynb +++ b/Programming_in_C/Chapter_18.ipynb @@ -27,19 +27,13 @@ "cell_type": "code", "collapsed": false, "input": [ - "#18.1.py\n", - "#Adding Debug statements in program\n", "\n", - "#Program logs will be saved in file- 18.1_logFile.txt\n", "\n", - "#Import library\n", "import logging\n", "\n", - "#Function to return sum of 3 numbers\n", "def process(i,j,k):\n", " return i+j+k\n", "\n", - "#Main()\n", "def main():\n", "\n", " logger = logging.getLogger()\n", @@ -66,7 +60,6 @@ " print(\"sum= %i\\n\"%process(arr[0],arr[1],arr[2]))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -112,15 +105,10 @@ "cell_type": "code", "collapsed": false, "input": [ - "#18.2.py\n", - "#Compiling in Debug \n", "\n", - "#Program logs will be saved in file- 18.2_logFile.txt\n", "\n", - "#Import Libraries\n", "import logging,sys\n", "\n", - "#Function to return product of two numbers\n", "def process(i1,i2):\n", "\n", " global logger \n", @@ -130,7 +118,6 @@ " return val\n", "\n", "\n", - "#Main()\n", "def main():\n", "\n", " global logger\n", @@ -173,7 +160,6 @@ " #print(\"product = %i\\n\" %( process (arg1, arg2)))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -236,23 +222,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#18.3.py\n", - "#Compiling in Debug--version2\n", "\n", - "#Program logs will be saved in file- 18.3_logFile.txt\n", "\n", - "#Using different logging levels\n", - "#DEBUG Detailed information, typically of interest only when diagnosing problems.\n", - "#INFO Confirmation that things are working as expected.\n", - "#WARNING An indication of some problem in the near future (e.g.'disk space low')\n", - "#ERROR Due to a more serious problem, the software has not been able to perform some function.\n", - "#CRITICAL A serious error, indicating that the program itself may be unable to continue running.\n", "\n", "\n", - "#Import Libraries\n", "import logging,sys\n", "\n", - "#Function to return product of two numbers\n", "def process(i1,i2):\n", "\n", " global logger \n", @@ -262,7 +237,6 @@ " return val\n", "\n", "\n", - "#Main()\n", "def main():\n", "\n", " global logger\n", @@ -305,7 +279,6 @@ " #print(\"product = %i\\n\" %( process (arg1, arg2)))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -368,10 +341,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#18.4.py\n", - "#A simple program for use with pdb(gdb like python debugger)\n", "\n", - "#Main()\n", "def main():\n", " \n", " #Variable Declaration\n", @@ -386,7 +356,6 @@ " print(\"sum = %i\\n\"%(sum))\n", " \n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n" @@ -417,10 +386,7 @@ "cell_type": "code", "collapsed": false, "input": [ - "#18.5.py\n", - "#Working more with pdb\n", "\n", - "#Class Declaration\n", "class date:\n", " def __init__(self,m,d,y): #Class constructor\n", " self.month=m\n", @@ -431,7 +397,6 @@ " x.day+=1\n", " return x\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Variable Declaration\n", @@ -446,7 +411,6 @@ " print(\"today= %d/%d/%d\"%(today.day,today.month,today.year))\n", "\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()\n", "\n", diff --git a/Programming_in_C/Chapter_19.ipynb b/Programming_in_C/Chapter_19.ipynb index d92a3f41..731d6d87 100644 --- a/Programming_in_C/Chapter_19.ipynb +++ b/Programming_in_C/Chapter_19.ipynb @@ -27,16 +27,12 @@ "cell_type": "code", "collapsed": false, "input": [ - "#19.1.py\n", - "#Working with fractions in python\n", "\n", - "#Class declaration\n", "class Fraction:\n", " def __init__(self): #Class constructor\n", " self.numerator=0\n", " self.denominator=0\n", "\n", - "#Main()\n", "def main():\n", "\n", " #Creating instance\n", @@ -46,7 +42,6 @@ "\n", " print(\"The Fraction is {0}/{1}\".format(myFract.numerator,myFract.denominator))\n", "\n", - "#Setting top level conditional script\n", "if __name__=='__main__':\n", " main()" ], |