{
 "metadata": {
  "name": "",
  "signature": "sha256:a2d2127f6a5ebfde55eb11899a94f93b6aeee78155a32ab8e434ae8b263ad3b3"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "10 : ARRAYS"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.2.1,page number:170"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "value = [6]\n",
      "\n",
      "for index in range(0,6):\n",
      "    print \"Enter Integer\"\n",
      "    value.append(int(input()))\n",
      "for index in range(0,7):\n",
      "    print \"Integer = \",value[index]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "4\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "6\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "12\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "6\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "7\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Integer\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "13\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Integer =  6\n",
        "Integer =  4\n",
        "Integer =  6\n",
        "Integer =  12\n",
        "Integer =  6\n",
        "Integer =  7\n",
        "Integer =  13\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.3.1, page number:170"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "value=[6,4,3,2,1]\n",
      "for index in xrange(5):\n",
      "    print \"Integer = \",value[index]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Integer =  6\n",
        "Integer =  4\n",
        "Integer =  3\n",
        "Integer =  2\n",
        "Integer =  1\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.3.2, page number:171"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "def MAX_SIZE_CONST():\n",
      "    return 123\n",
      "def TRAILER_CONST():\n",
      "    return -7777\n",
      "value=array.array('i',[])\n",
      "print \"Enter upto\",MAX_SIZE_CONST(),\"using\",TRAILER_CONST(),\"as trailer :\"\n",
      "print \"\"\n",
      "m=0\n",
      "for index in range(0,int(MAX_SIZE_CONST())):\n",
      "    item=int(input())\n",
      "    if(item == int(TRAILER_CONST())):\n",
      "        break\n",
      "    else:\n",
      "        value.append(item)\n",
      "        m+=1\n",
      "for index in range(0,m):\n",
      "    print \"Integer =\",value[index]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter upto 123 using -7777 as trailer :\n",
        "\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "2\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "3\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "4\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "-7777\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Integer = 1\n",
        "Integer = 2\n",
        "Integer = 3\n",
        "Integer = 4\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.4.1, page number:172"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "k=0\n",
      "sum=0.0\n",
      "def MAX_STUD():\n",
      "    return 20\n",
      "def ENDINP():\n",
      "    return -9999\n",
      "mark=array.array('i',(0 for i in range(0,MAX_STUD())))\n",
      "print \"enter upto\",MAX_STUD(),\"marks:\"\n",
      "readin=int(input())\n",
      "for index in range(0,MAX_STUD()):\n",
      "    if(readin != ENDINP()):\n",
      "        mark[index]=readin\n",
      "        readin=int(input())\n",
      "        k+=1\n",
      "for index in xrange(0,k):\n",
      "    sum=sum+mark[index]\n",
      "print \"Average Mark = \",sum/k\n",
      "    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "enter upto 20 marks:\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "34\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "66\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "78\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "65\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "43\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "23\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "12\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "88\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "-9999\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Average Mark =  51.125\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.5.1, page number:174"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "def MAX_SIZE():\n",
      "    return 10\n",
      "#str=array.array('i',(0 for i in range(0,MAX_SIZE()+1)))\n",
      "print \"Enter the 10 letter word.\"\n",
      "str=raw_input()\n",
      "r=[]\n",
      "for letter in str:\n",
      "    r.append(letter)\n",
      "r.reverse()\n",
      "print \"word = \",str\n",
      "print \"\".join(r)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter the 10 letter word.\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "madurai\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "word =  madurai\n",
        "iarudam\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.6.1, page number:175"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import array\n",
      "def MAX_SIZE():\n",
      "    return 20\n",
      "size=0\n",
      "variable =array.array('i',[])\n",
      "while True:\n",
      "    print \"Array-size : ?\"\n",
      "    size=int(input())\n",
      "    if size>1 and size<MAX_SIZE():\n",
      "        break\n",
      "print \"Enter Numbers:\"\n",
      "for k in range(0,size):\n",
      "    m=int(input())\n",
      "    variable.append(m)\n",
      "\n",
      "variable= array.array('i',sorted(variable))\n",
      "\n",
      "print \"Sorted Array is:\"\n",
      "for k in range(0,size):\n",
      "    print variable[k],\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Array-size : ?\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "9\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enter Numbers:\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "7\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "10\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "43\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": [
        "6\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "14\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "8\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "9\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Sorted Array is:\n",
        "-5 0 6 7 8 9 10 14 43\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "10.7.1,page number:176"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pox =[[0 for x in range(4)]for x in range(6)]\n",
      "pox[0]=3,5,7,9,12,20\n",
      "pox[1]=10,13,17,21,25,40\n",
      "pox[2]=15,18,22,26,30,45\n",
      "pox[3]=17,20,23,27,32,46\n",
      "\n",
      "def read_city():\n",
      "    running=True\n",
      "    while running:\n",
      "        print \"Which city?\"\n",
      "        city=int(input())\n",
      "        if city == 0:\n",
      "            exit(1)\n",
      "        if city<4 or city>4 :\n",
      "            running=False\n",
      "    return city\n",
      "def read_year():\n",
      "    running=True\n",
      "    while running:\n",
      "        print \"Which year?\"\n",
      "        year=int(input())\n",
      "        if year>1950 or year<2000 :\n",
      "            running=False\n",
      "    return year\n",
      "def pop(x,y):\n",
      "    global pox\n",
      "    return pox[x-1][(y-1950)/10]\n",
      "\n",
      "def output_city():\n",
      "    if city == 1:\n",
      "        return \"Madurai\"\n",
      "    elif city == 2:\n",
      "        return \"Madras\"\n",
      "    elif city == 3:\n",
      "        return \"Bombay\"\n",
      "    elif city == 4:\n",
      "        return \"Calcutta\"\n",
      "        \n",
      "runnable=True\n",
      "city=read_city()\n",
      "while runnable :\n",
      "    year=read_year()\n",
      "    print \"Population in \",year,\"of\",output_city(),\"is\",pop(city,year),\"Lakhs\"\n",
      "    city =read_city()\n",
      "    if city == 0:\n",
      "        runnable=False"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Which city?\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "3\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Which year?\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1990\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Population in  1990 of Bombay is 30 Lakhs\n",
        "Which city?\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "0\n"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}