diff options
author | hardythe1 | 2015-05-05 14:21:39 +0530 |
---|---|---|
committer | hardythe1 | 2015-05-05 14:21:39 +0530 |
commit | fba055ce5aa0955e22bac2413c33493b10ae6532 (patch) | |
tree | be70ef4fccd07c9c88de778014219201b4ea971f /Computer_Concepts_and_C_Programming/chapter10.ipynb | |
parent | 67068710030ddd6b6c809518c34af2e04e0bf7ca (diff) | |
download | Python-Textbook-Companions-fba055ce5aa0955e22bac2413c33493b10ae6532.tar.gz Python-Textbook-Companions-fba055ce5aa0955e22bac2413c33493b10ae6532.tar.bz2 Python-Textbook-Companions-fba055ce5aa0955e22bac2413c33493b10ae6532.zip |
add books
Diffstat (limited to 'Computer_Concepts_and_C_Programming/chapter10.ipynb')
-rwxr-xr-x | Computer_Concepts_and_C_Programming/chapter10.ipynb | 600 |
1 files changed, 600 insertions, 0 deletions
diff --git a/Computer_Concepts_and_C_Programming/chapter10.ipynb b/Computer_Concepts_and_C_Programming/chapter10.ipynb new file mode 100755 index 00000000..8be3d9ff --- /dev/null +++ b/Computer_Concepts_and_C_Programming/chapter10.ipynb @@ -0,0 +1,600 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2cafa3e908c942f24f0641c416de64e3b7ea34b141a866aae200a7ad053e7f3e"
+ },
+ "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
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |