{ "metadata": { "name": "", "signature": "sha256:95ddab2248de9e7055a4dff19cd18b277d7ba7ab8ace5be6bff568b621024b03" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "\n", "Chapter 8 : Pointers" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 8.1, Page No 179" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from ctypes import *\n", "\n", "iNo=c_int\n", "pNo = id(iNo)\n", "dPrice=dTotal=float\n", "pPrice=id(dPrice)\n", "pTotal=id(dTotal)\n", "cName=range(20)\n", "pName=id(cName)\n", "pName = raw_input(\"Enter your name: \")\n", "pNo = int(raw_input(\"Enter quantity: \"))\n", "pPrice = float(raw_input(\"and price: \"))\n", "pTotal = pNo * pPrice\n", "print \"Dear \" + pName + \", your price is \" + str(pTotal) + \" kr.\"" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Enter your name: chirag\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Enter quantity: 10\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "and price: 100\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Dear chirag, your price is 1000.0 kr.\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 8.2, Page No 182" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iSal=[14000,15000,16000,17000,18000,19000]\n", "pSal = id(iSal)\n", "dTax=[0.32,0.34,0.35,0.36,0.365,0.37]\n", "pTax=id(dTax)\n", "print \"Salary Tax\"\n", "for i in range(6):\n", " print str(iSal[i])+\" \",str(iSal[i]*dTax[i])\n", " i=i+1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Salary Tax\n", "14000 4480.0\n", "15000 5100.0\n", "16000 5600.0\n", "17000 6120.0\n", "18000 6570.0\n", "19000 7030.0\n" ] } ], "prompt_number": 10 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 8.3, Page No 185" ] }, { "cell_type": "code", "collapsed": false, "input": [ "def find(s):\n", " for p in range(len(s)):\n", " if(s[p]=='@'):\n", " print \"It is an email address\"\n", " p=p+1\n", "\n", "#cString=range(9)\n", "pString=id(cString)\n", "cString=raw_input(\"Enter A text: \")\n", "find(cString)" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Enter A text: hello@gmail.com\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "It is an email address\n" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 8.4, Page No 188" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNumber=int(raw_input(\"How many product will be entered? \"))\n", "\n", "for i in range(iNumber):\n", " pNo = id(iNumber)\n", " print pNo\n", " pNO = pNo + 1\n", "pNo = pNo - iNumber\n", "for i in range(iNumber):\n", " print id(pNO)\n", " pNo = pNO + 1\n", "pNo = pNo - iNumber\n", "del pNo " ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "How many product will be entered? 5\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "3848360\n", "3848360\n", "3848360\n", "3848360\n", "3848360\n", "51980880\n", "51980880\n", "51980880\n", "51980880\n", "51980880\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 8.5, Page No 189" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNo = 5\n", "cName = range(iNo)\n", "print \"Enter the name of 5 course mates: \"\n", "for i in range(iNo):\n", " print \"Mate no. \" ,i+1\n", " temp = raw_input(\"Mate name: \")\n", " cName.append(temp)\n", "for j in range(iNo):\n", " print cName[j]\n", "for k in range(iNo):\n", " del cName[k] " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Enter the name of 5 course mates: \n", "Mate no. 1\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Mate name: a\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Mate no. 2\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Mate name: b\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Mate no. 3\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Mate name: c\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Mate no. 4\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Mate name: d\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Mate no. 5\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Mate name: e\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }