{ "metadata": { "name": "", "signature": "sha256:8f653af2e0b44c81d67d541bdc64870a18188d9d1a401e0b96b1b859a01ca59f" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapeter 2 : Variables" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.1, Page No 29" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNo = raw_input(\"Specify Quantity: \")\n", "print iNo" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Specify Quantity: 10\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "10\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.2, Page No 31" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNo = raw_input(\"Specify Quantity: \")\n", "print \"You entered\", iNo" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "specify quantity22\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "You entered 22\n" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.3, Page No 32" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNo = raw_input(\"specify quantity: \")\n", "dPrice = raw_input(\"Specify unit Price: \")\n", "print \"You entered the quantity \", iNo , \" and the price \" , dPrice" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "specify quantity: 5\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Specify unit Price: 12.45\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "You entered the quantity 5 and the price 12.45\n" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.4, Page No 36" ] }, { "cell_type": "code", "collapsed": false, "input": [ "dTaxPerc = 25.0\n", "iNo = int(raw_input(\"Specify Quantity: \"))\n", "dUnitPr = float(raw_input(\"Specify Unit Price: \"))\n", "dPriceExTax = dUnitPr * iNo\n", "dTax = dPriceExTax * dTaxPerc / 100\n", "dCustPrice = dPriceExTax + dTax\n", "print \"INVOICE\"\n", "print \"========\"\n", "print \"Quantity: \", iNo\n", "print \"Price per Unit: \", dUnitPr\n", "print \"Total Price: \", dCustPrice\n", "print \"Tax: \",dTax" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Specify Quantity: 5\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Specify Unit Price: 12.4\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "INVOICE\n", "========\n", "Quantity: 5\n", "Price per Unit: 12.4\n", "Total Price: 77.5\n", "Tax: 15.5\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.5, Page No 38" ] }, { "cell_type": "code", "collapsed": false, "input": [ "iNoOfSec = int(raw_input(\"Speicfy No. of Seconds: \"))\n", "iNoOfMin = iNoOfSec / 60\n", "iSecLeft = iNoOfSec % 60\n", "iNoOfHours = iNoOfMin / 60\n", "iMinLeft = iNoOfMin % 60\n", "print \"Number of hours = \", iNoOfHours\n", "print \"Number of Minutes = \", iNoOfMin\n", "print \"Number of Seconds = \", iSecLeft" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Speicfy No. of Seconds: 10000\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "Number of hours = 2\n", "Number of Minutes = 166\n", "Number of Seconds = 40\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 2.6, Page No 41" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import random\n", "iNo = 5\n", "iRoll1 = random.randint(0,100) % 6 + 1\n", "iRoll2 = random.randint(0,100) % 6 + 1\n", "iRoll3 = random.randint(0,100) % 6 + 1\n", "iRoll4 = random.randint(0,100) % 6 + 1\n", "iRoll5 = random.randint(0,100) % 6 + 1\n", "dAverage = float(iRoll1 + iRoll2 + iRoll3 + iRoll4 + iRoll5) / iNo;\n", "print \"Number of Rolls: \", iNo\n", "print \"Average Score: \", dAverage" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Number of Rolls: 5\n", "Average Score: 3.0\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }