{ "metadata": { "name": "", "signature": "sha256:66fb80b57a6473ffca1e8f425382d8ae7bda3cbb5a42b72a09573b1379da5aa8" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter 15: Writing Large Programs" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example justify.c, Page 359\n", "Other files- word.h, line.h, word.c, line.c" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import textwrap\n", "quote2=''\n", "quote= (' C is quirky, flawed, and an '\n", " 'enormous success. Although accidents of history '\n", " ' surely helped, it evidently satisfied a need '\n", " ''\n", " 'for a system implementation language efficient '\n", " 'enough to displace assembly language, '\n", " ' yet sufficiently abstract and fluent to describe '\n", " ' algorithms and interactions in a wide variety '\n", " 'of environments.'\n", " ' -- Dennis M. Ritchie')\n", "for i in quote:\n", " if (len(i)>20):\n", " i=(i[:20] + '*')\n", " quote2=quote2+i\n", "quote2=' '.join(quote2.split()) \"\"\"Python has inbuilt functions for removing \n", "white spaces and textwrap, justifying text hence reduces the amount of code as required in C\"\"\"\n", "quotee= textwrap.fill(quote2)\n", "print quotee" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "C is quirky, flawed, and an enormous success. Although accidents of\n", "history surely helped, it evidently satisfied a need for a system\n", "implementation language efficient enough to displace assembly\n", "language, yet sufficiently abstract and fluent to describe algorithms\n", "and interactions in a wide variety of environments. -- Dennis M.\n", "Ritchie\n" ] } ], "prompt_number": 16 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }