Comp 150
Goals:
I've provided you with that first page, fact.html,
and a starter cgi script
fact.cgi 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/cgi_demos/factskel,
also generates one or two rows of the table, but you should delete those. The comments in fact.cgi should make that clear.
What you need to do is to modify the cgi program so that it prints the correct rows. A full working version can be observed at xenon.cs.luc.edu/~pld/cgi_demos/fact. The program contains:
<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, and where the value of x in this case would be 6. Start with
<td> 6 </td>
<td> 720 </td>
</tr>
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. Mostly, just be aware that the form data itself is received in string format, and has to be converted to numeric format before you can use it.
Other improvements could be to print the second column in bold, or add a third column.
To run programs, we're going to use a small python-based webserver, in webserver.zip. (which includes fact.html and fact.cgi). Download and unzip into an appropriate work directory, and double-click on the webserver.bat file to start it. Note that it starts on port 8000, not the usual port 80, so web requests have to have ":8000" embedded in them at the appropriate place. Your first step should be to see that you can retrieve index.html; the full url is http://localhost:8000/index.html but localhost:8000 should also work. Be aware that the small webserver is not always very good about reporting errors accurately.Email me your python file fact.cgi.