{ "metadata": { "name": "", "signature": "sha256:9985251f9ed527f5f6157524d1241d5f81fd588714602adf2cf638e46fdde236" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Hour 9: Working with data and Math functions" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 9.1, Page No.144" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Value in the textbook for 0xFF is wrong\n", "ch = \"0xFF\"\n", "x = \"0xFFFF\"\n", "y = \"0xFFFF\"\n", "print \"The decimal of signed 0xFF is \", int(ch, 16)\n", "print \"The decimal of signed 0xFFFF is \", int(x, 16)\n", "print \"The decimal of unsigned 0xFFFF is \", int(y, 16)\n", "print \"The hex of decimal 12345 is 0x%x\" %(12345)\n", "#answer in textbook for -12345 is wrong\n", "print \"The hex of decimal -12345 is 0x%x\" %(-12345)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The decimal of signed 0xFF is 255\n", "The decimal of signed 0xFFFF is 65535\n", "The decimal of unsigned 0xFFFF is 65535\n", "The hex of decimal 12345 is 0x3039\n", "The hex of decimal -12345 is 0x-3039\n" ] } ], "prompt_number": 17 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 9.2, Page No.146" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "print \"The size of short int is:\",sys.getsizeof(65535)\n", "print \"The size of long int is:\",sys.getsizeof(65535*65535)\n", "print \"The size of float is:\",sys.getsizeof(0.0)\n", "# As python has no datatype like double, so that portion of program has not writeen here." ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The size of short int is: 12\n", "The size of long int is: 18\n", "The size of float is: 16\n" ] } ], "prompt_number": 21 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Exmaple 9.3, Page No.147" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import array\n", "x=0xFFFF\n", "y=0xFFFF\n", "s=0xFFFFFFFFl\n", "t=0xFFFFFFFFL\n", "print \"The short int of 0xFFFF is {:d}\".format(x)\n", "print \"The unsigned int of 0xFFFF is {:d}\".format(y)\n", "print \"The long int of 0xFFFFFFFFl is {:d}\".format(s)\n", "print \"The long int of 0xFFFFFFFFl is {:d}\".format(t)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The short int of 0xFFFF is 65535\n", "The unsigned int of 0xFFFF is 65535\n", "The long int of 0xFFFFFFFFl is 4294967295\n", "The long int of 0xFFFFFFFFl is 4294967295\n" ] } ], "prompt_number": 30 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 9.4, Page No.150" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import math\n", "x=45.0\n", "x=x*3.141593/180.0\n", "print \"The sine of 45 is: \",math.asin(x)\n", "print \"The sine of 45 is: \",math.acos(x)\n", "print \"The tangent of 45 is: \",math.atan(x)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The sine of 45 is: 0.903339250676\n", "The sine of 45 is: 0.667457076119\n", "The tangent of 45 is: 0.665773803591\n" ] } ], "prompt_number": 33 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 9.5, Page No.151" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import math\n", "x=64.0\n", "y=3.0\n", "z=0.5\n", "print \"pow(64.0,3.0) returns {:7.0f}\".format(math.pow(x,y))\n", "print \"sqrt(64.0) returns {:2.0f}\".format(math.sqrt(x))\n", "print \"pow(64.0,0.5) returns {:2.0f}\".format(math.pow(x,z))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "pow(64.0,3.0) returns 262144\n", "sqrt(64.0) returns 8\n", "pow(64.0,0.5) returns 8\n" ] } ], "prompt_number": 36 } ], "metadata": {} } ] }