{
 "metadata": {
  "name": "Chapter XIII"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 13: The preprocessor"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Program 13.1, Page number: 300"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "global YES\n",
      "global NO\n",
      "YES=1\n",
      "NO=0\n",
      "\n",
      "\n",
      "def isEven(number):\n",
      "        global YES\n",
      "        global NO\n",
      "\n",
      "        if(number%2==0):\n",
      "                answer=YES\n",
      "        else:\n",
      "                answer=NO\n",
      "\n",
      "        return answer\n",
      "\n",
      "def main():\n",
      "        global YES\n",
      "        global NO\n",
      "\n",
      "        #Calculation/Result\n",
      "        if(isEven(17)==YES):\n",
      "                print(\"YES\")\n",
      "        else:\n",
      "                print(\"NO\")\n",
      "\n",
      "        \n",
      "        if(isEven(20)==YES):\n",
      "                print(\"YES\")\n",
      "        else:\n",
      "                print(\"NO\")\n",
      "\n",
      "\n",
      "if __name__=='__main__':\n",
      "        main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "NO\n",
        "YES\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Program 13.2, Page number: 302"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "global PI\n",
      "PI= 3.141592654\n",
      "\n",
      "\n",
      "def area(r):\n",
      "        global PI\n",
      "        return (PI*r*r)\n",
      "\n",
      "def circumference(r):\n",
      "        global PI\n",
      "        return (2*PI*r)\n",
      "\n",
      "def volume(r):\n",
      "        global PI\n",
      "        return (1.33 * PI*r*r*r)\n",
      "        \n",
      "\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",
      "if __name__=='__main__':\n",
      "        main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "radius=1   3.141592654   6.283185308   4.17831822982\n",
        "radius=4.98   77.9127544563   31.2902628338   516.047337866\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Program 13.3, Page number: 314"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "global QUARTS_PER_LITER\n",
      "QUARTS_PER_LITER=1.05687\n",
      "\n",
      "def main():\n",
      "        global QUARTS_PER_LITER                         #Global Reference\n",
      "\n",
      "        print(\"***Liters to galons***\")\n",
      "        print(\"Enter the number of Litres\")\n",
      "        liters=12                                       #liters=raw_input()\n",
      "\n",
      "        gallons=float(liters)*QUARTS_PER_LITER/4.0      #calculation\n",
      "\n",
      "        print(\"{0} Liters = {1} gallons\".format(liters,gallons))\n",
      "\n",
      "if __name__=='__main__':\n",
      "        main()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "***Liters to galons***\n",
        "Enter the number of Litres\n",
        "12 Liters = 3.17061 gallons\n"
       ]
      }
     ],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}