{
 "metadata": {
  "name": "",
  "signature": "sha256:6065d96194d011c72f0a8e96e52a07b9854f652b99dbacaf2f793d33a2f5e84b"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "9 : DECISION MAKING,BREAKING BRANCHING AND LOOPING"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.1.1,page number:156"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Type an Integer\"\n",
      "numb=int(input())\n",
      "if numb<=5:\n",
      "    print \"Good Choice!\"\n",
      "print \"Thank You!\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Type an Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "3\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Good Choice!\n",
        "Thank You!\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.2.1,page number:157"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Enter year : \"\n",
      "year= int(input())\n",
      "if year%4 == 0 and year%100 != 0 or year%400 == 0:\n",
      "    print year,\"is a leap year\"\n",
      "else:\n",
      "    print year,\"is not a leap year\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter year : \n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1990\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1990 is not a leap year\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.4.1,page number : 158"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Enter choice of city(1-4)\"\n",
      "city = int(input())\n",
      "if city == 1:\n",
      "    print \"Madurai\"\n",
      "elif city == 2:\n",
      "    print \"Chennai\"\n",
      "elif city == 3:\n",
      "    print \"Mumbai\"\n",
      "elif city == 4:\n",
      "    print \"Calcutta\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter choice of city(1-4)\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "3\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mumbai\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.6.1,page number : 161"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "i =20\n",
      "variable =array.array('i',[])\n",
      "size = 0\n",
      "\n",
      "def get_array_size():\n",
      "    print \"Array-size :\"\n",
      "    global size\n",
      "    size=int(input())\n",
      "    if size<1 or size>i :\n",
      "        get_array_size()\n",
      "    \n",
      "def input_fetch():\n",
      "    global size\n",
      "    global variabless\n",
      "    for k in range(0,size):\n",
      "        m=int(input())\n",
      "        variable.append(m)\n",
      "    return\n",
      "\n",
      "def sort_list():\n",
      "    global variable\n",
      "    variable= array.array('i',sorted(variable))\n",
      "    \n",
      "    return\n",
      "    \n",
      "def output():\n",
      "    for k in range(0,size):\n",
      "        print variable[k],\n",
      "    return\n",
      "\n",
      "def even(number):\n",
      "    if number/2 == 0:\n",
      "        return 1\n",
      "    else:\n",
      "        return 0\n",
      "\n",
      "get_array_size()\n",
      "input_fetch()\n",
      "sort_list()\n",
      "print \"The sorted list is :\"\n",
      "output()\n",
      "print \"\\nMedian : \",\n",
      "\n",
      "median=round((variable[(size/2)-1]+variable[size/2])/2,3) if even(size)  else float(variable[size/2])\n",
      "print median"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Array-size :\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "10\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "7\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "6\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "8\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "-4\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "0\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "5\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "13\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "17\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "25\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "6\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The sorted list is :\n",
        "-4 0 5 6 6 7 8 13 17 25 \n",
        "Median :  7.0\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.8.1,page number:163"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "index = 1\n",
      "while index<12:\n",
      "    print \"This is line \",index\n",
      "    index+=1\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "This is line  1\n",
        "This is line  2\n",
        "This is line  3\n",
        "This is line  4\n",
        "This is line  5\n",
        "This is line  6\n",
        "This is line  7\n",
        "This is line  8\n",
        "This is line  9\n",
        "This is line  10\n",
        "This is line  11\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.9.1,page number:164"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Enter Integer\"\n",
      "total_sum=0\n",
      "numb=int(input())\n",
      "while numb>0:\n",
      "    digit=numb %10\n",
      "    total_sum+=digit\n",
      "    numb/=10\n",
      "print \"Sum is \",total_sum"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1776\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Sum is  21\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.9.2,page number:165"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Enter Integer:\"\n",
      "numb=int(input())\n",
      "print numb,\"is reversed as \",\n",
      "while numb>0:\n",
      "    digit=numb%10\n",
      "    print digit,\n",
      "    numb/=10\n",
      "print \"\\n\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer:\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1234\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1234 is reversed as  4 3 2 1 \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.10.1,page number:166"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for index in range(1,11):\n",
      "    print \" line \",index"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " line  1\n",
        " line  2\n",
        " line  3\n",
        " line  4\n",
        " line  5\n",
        " line  6\n",
        " line  7\n",
        " line  8\n",
        " line  9\n",
        " line  10\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.10.2,page number:166"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print \"Result\"\n",
      "print \"Index     Index Squared\"\n",
      "print \"_____     _____________\"\n",
      "for  index in range(1,11):\n",
      "    print index,\"         \",index*index"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Result\n",
        "Index     Index Squared\n",
        "_____     _____________\n",
        "1           1\n",
        "2           4\n",
        "3           9\n",
        "4           16\n",
        "5           25\n",
        "6           36\n",
        "7           49\n",
        "8           64\n",
        "9           81\n",
        "10           100\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "9.10.3,page number:167"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "total_sum=0\n",
      "value=100\n",
      "for index in range(1,value+1):\n",
      "    total_sum+=index\n",
      "print \"Sum of 1 to \",value,\" = \",total_sum"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Sum of 1 to  100  =  5050\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": []
    }
   ],
   "metadata": {}
  }
 ]
}