CS106L Introduction to Computing and Programming in Python (Lab)
Fall 2008

Lab 12

Code for Lab 12

Home Assignment

  1. Adapting the code from Lab 12 and adding to this code (documents.py), create a function textPage that returns a string representation of a page listing each sample of the documents with their corresponding titles with the main title at the top. This should be done programatically just like during Lab 12. E.g.
    Great Documents of the United States
    
    Declaration of Independence
    
    We hold these truths to be self-evident, that all men are created
    equal, that they are endowed by their Creator with certain unalienable
    Rights, that among these are Life, Liberty and the pursuit of
    Happiness.
    
    Preamble to the Constitution
    
    We the People of the United States, in Order to form a more perfect
    Union, establish Justice, insure domestic Tranquility, provide for the
    common defence, promote the general Welfare, and secure the Blessings
    of Liberty to ourselves and our Posterity, do ordain and establish
    this Constitution for the United States of America.
    
    Gettysburg Address
    
    Four score and seven years ago our fathers brought forth on this
    continent a new nation, conceived in Liberty, and dedicated to the
    proposition that all men are created equal.
            

  2. Similar to textPage, create a function webPage that returns a string representation of a page listing each sample of the documents with their corresponding titles with the main title at the top. However, this string representation should be formatted as HTML. E.g.
    <html>
    <body>
    <h1>Great Documents of the United States</h1>
    
    <h2>Declaration of Independence</h2>
    
    <p>
    We hold these truths to be self-evident, that all men are created
    equal, that they are endowed by their Creator with certain unalienable
    Rights, that among these are Life, Liberty and the pursuit of
    Happiness.
    </p>
    
    <h2>Preamble to the Constitution</h2>
    
    <p>
    We the People of the United States, in Order to form a more perfect
    Union, establish Justice, insure domestic Tranquility, provide for the
    common defence, promote the general Welfare, and secure the Blessings
    of Liberty to ourselves and our Posterity, do ordain and establish
    this Constitution for the United States of America.
    </p>
    
    <h2>Gettysburg Address</h2>
    
    <p>
    Four score and seven years ago our fathers brought forth on this
    continent a new nation, conceived in Liberty, and dedicated to the
    proposition that all men are created equal.
    </p>
    </body>
    </html>
            
EXTRA CREDIT: Have both your functions return documents with the sections in random order.


Last modified: 11-13-2008
By: David O'Gwynn