Lab 8: cgi programming in python on xenon

Comp 150, Dordal, March 24, 2006

Goals:

Table of factorials

You can see what the end result is supposed to do at xenon.cs.luc.edu/~pld/fact: The first page prompts you for numbers M and N, and when you click submit you get a table of factorials from M to N.

I've provided you with that first page, fact.html, and a starter cgi script fact.cgi (click here to view) that contains the basics for creating the output page, with table. The starter, which you can observe in action at xenon.cs.luc.edu/~pld/fact2, also generates one or two rows of the table, but you should delete that.

What you need to do is to modify the cgi program so that it prints the correct rows. The program contains:

You need to provide the printrow(x,y) function that, if x and y have values 6 and 720 respectively, will produce four lines as follows:
    <tr>
    <td> 6 </td>
    <td> 720 </td>
    </tr>
This is the HTML that generates one row of the table. Hint: to get the second line above, use print "<td>, x, </td>", with quotes as shown. Start with
     def printrow(x,y):
as shown in the fact.cgi starter file.

You will then need to change main to call your printrow function, in a for loop. Do this between printprolog and printepilog; get rid of the line I had there).

    for i in range(M, ???):
        printrow(i, ???)

If you want to get fancy, check that the strings Mstr and Nstr consist of digits only before you convert them via M=int(Mstr), etc. If there are nondigits, conversion with int() will cause an error.

Other improvements could be to print the second column in bold, or add a third column.

I will give you your username on xenon. The password is the first five letters followed by ".2006"; eg "pdord.2006". Working on xenon.cs.luc.edu is something of a pain; here are some pointers.

Email me your python file fact.cgi, or give me an in-class demo.