{ "metadata": { "name": "", "signature": "sha256:4ee1b1671641fa0922389d9bf11b94f42d9755534b4f0476bbe2f9ceb3b1bc7e" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 19: Ancient compilers" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 19.1, Page number: 385" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Function declaration\n", "def area (width, height) :\n", " return width * height\n", "\n", "# Calculation and result\n", "size = area (3.0, 2)\n", "print ('Area is %f\\n' % size)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Area is 6.000000\n", "\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 19.2, Page number: 386" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Function declaration\n", "def square (s) :\n", " return s * s\n", "\n", "# Calculation and result\n", "i = square (5)\n", "print ('i is %d\\n' % i)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "i is 25\n", "\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 19.3, Page number: 386" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Function declaration\n", "def sum (i1, i2, i3) :\n", " return i1 + i2 + i3\n", "\n", "# Calculation and result\n", "print ('Sum is %d\\n' % sum (1, 2, 3))" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Sum is 6\n", "\n" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 19.4, Page number: 387" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Variable declaration\n", "first = 'John'\n", "last = 'Doe'\n", "\n", "# Calculation and result\n", "full = first + ' ' + last\n", "print ('The name is %s\\n' % full)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The name is John Doe\n", "\n" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Example 19.5, Page number: 390" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# Function declaration\n", "def area (width, height) :\n", " return width * height\n", "\n", "# Calculation and result\n", "size = area (3.0, 2.0)\n", "print ('Area is %f\\n' % size)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Area is 6.000000\n", "\n" ] } ], "prompt_number": 5 } ], "metadata": {} } ] }