{ "metadata": { "name": "", "signature": "sha256:d5e2b3b4e2eecb1f7195196f8d754ec6a4ed41953a9ae9d18560339b9d5ef6ea" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 4: Constants, Variables & Datatypes" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "example 4.1, page no. 50" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "intnum = int(raw_input(\"Enter an Integer: \"))\n", "floatnum = float(raw_input(\"Enter a Float: \"))\n", "\n", "print \"intnum = \", intnum\n", "print \"floatnum = \", floatnum" ], "language": "python", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Enter an Integer: 3\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "Enter a Float: 6.9\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "intnum = 3\n", "floatnum = 6.9\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "example 4.2, page no. 54" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "print \"Variables Created\"\n", "c = \"x\"\n", "b = 50\n", "s = 1996\n", "i = 123456789\n", "l = 1234567654321L\n", "f1 = 3.142\n", "f2 = 1.2e-5\n", "d2 = 0.000000987\n", "\n", "print \"c = \", c\n", "print \"b = \", b\n", "print \"s = \", s\n", "print \"i = \", i\n", "print \"l = \", l\n", "print \"f1 = \", f1\n", "print \"f2 = \", f2\n", "print \"d2 = \", d2\n", "\n", "print \"Types Converted\"\n", "#there is no short type in python\n", "s1 = b\n", "s2 = i\n", "n1 = float(l)\n", "m1 = int(f1)\n", "\n", "print \"s1 = \", s1\n", "print \"s2 = \", s2\n", "print \"n1 = %.5e\"% n1\n", "print \"m1 = \", m1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Variables Created\n", "c = x\n", "b = 50\n", "s = 1996\n", "i = 123456789\n", "l = 1234567654321\n", "f1 = 3.142\n", "f2 = 1.2e-05\n", "d2 = 9.87e-07\n", "Types Converted\n", "s1 = 50\n", "s2 = 123456789\n", "n1 = 1.23457e+12\n", "m1 = 3\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "example 4.3, page no. 56" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "for i in range(1, 10):\n", " for j in range(1, i+1):\n", " print i,\n", " print \"\"\n", "print \"Screen Display Done\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1 \n", "2 2 \n", "3 3 3 \n", "4 4 4 4 \n", "5 5 5 5 5 \n", "6 6 6 6 6 6 \n", "7 7 7 7 7 7 7 \n", "8 8 8 8 8 8 8 8 \n", "9 9 9 9 9 9 9 9 9 \n", "Screen Display Done\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }