Craft 5

Beautiful Code
Ka-Ping Yee

Make sure you understand the material in Explore 5 before you do this assignment.

This assignment will be done in partners.

Jacob — Varun
Karl — Morgan
Nadia — Rosie
Nerissa — Jun
Peter — Adam
Omair — Calvin
Kevin — Peterson
Jason — Chris
Richard — David
Hunter — Thanh
Scott — Derek


~~~~~~ THE ASSIGNMENT ~~~~~~


There was just a protest march on Sunday, and i just heard that there's going to be a virtual march thingie on my birthday, so my activist juices are all riled up. So let's do the Berkeley thing.

Working with your partner, set up an online petition. There will be three parts:

  1. petition.html — an HTML page that displays the petition, and provides a form where a visitor can add their name. Accept at least a couple of fields — say, name, city, and state. Feel free to add more if you like. (The petition can be for anything. Be creative.)
  2. addname.cgi — a CGI script that accepts the input from the form. (It can display anything, like just a "Thank you" message. Its main job is to store the name that was entered.)
  3. shownames.cgi — a CGI script that shows how many people of signed, and displays the list of people who have signed. (When showing the number of people who have signed, please avoid ungrammatical constructions like "1 people have signed this petition." Do something pleasant.)

Set these files up in the public_html area in your cs198 account.

The list of names should be recorded in a file on disk. Use the pickle module to help you store the information. Your script runs with permission as your username, so you should put this file in your home directory on the EECS Instructional machines.

In order to read data out of a file produced by pickle.dump() when there might be a varying number of items stored in the file, you need to be able to detect reaching the end of the file. As you saw in the lab exercises, Python throws an EOFError when you hit the end of the file. To detect this error safely without aborting your program, use the try statement:

try:
    data = pickle.load(file)
    # now do something with the data
except EOFError:
    # no more records in the file; it's time to stop reading

The except EOFError clause is executed when an EOFError occurs inside the corresponding try block. The EOFError is a kind of exception (you may recognize this term from Java), and this try...except construction is called an exception handler. We'll talk more about exceptions in the next class.

When you're all done, log in to submit the assignment:


This assignment is due on Monday 24 February at 6 pm. You get a bonus if the assignment is submitted at least 24 hours early.