CMPT 165 Lab 7

This lab is intended to get you started with Python.

  1. If you haven't already, download and install Python. (Of course, if you're working in a lab on-campus it's already installed.

    Open up IDLE. (In Windows, select Start -> Programs -> Python -> IDLE (Python GUI)). Create an editor window (where you type your programs) by selecting File -> New Window.

    Type (or copy-and-paste) this code into the editor window. Save it as first.py.

    print "I'm a Python program."
    print "Outta my way!"

    Press F5 (or select Run -> Run Module) to run the program.

  2. Modify first.py so it prints this instead:

    I'm a Python program.
    This course is "CMPT 165".

    In order to print the double-quotes in the second line, you will have to use single-quotes to enclose the string: 'This course is "CMPT 165".'

  3. Create a Python program webtest.py that prints this (making sure there is a blank line after the first line):

    Content-type: text/html

    <html>
    <head>
    <title>Web Script</title>
    </head>
    <body>
    <h1>Web Script</h1>
    <p>I'm a dynamically generated web page.</p>
    </body>
    </html>

    Check your program in IDLE first to make sure it runs and prints text like the above.

    Upload this file to your web space on the course web server. Visit the page in your web browser. The URL will be something like this:

    http://cmpt165.csil.sfu.ca/~userid/webtest.py

    The server is set up so that Python programs (.py files) are executed and their output is sent to the browser. (Compare .html files, where the content of the file is sent as-is.)

When you are done the above create a text file named handin.txt using your favourite text editor. Write your name, student number, SFU e-mail ID, and the URL of the webtest.py file you uploaded to the server. Compress (using zip or any other compression utility) your handin.txt file along with the first.py file you created in part 2 and the webtest.py file you created in part 3 of this lab and submit the compressed file using the submission server.

Note: Your first.py file should not be uploaded to the web-server since the server will attempt to execute it.