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/Chapter_06.ipynb | |
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/Chapter_06.ipynb')
-rw-r--r-- | Programming_in_C/Chapter_06.ipynb | 53 |
1 files changed, 0 insertions, 53 deletions
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" ], |