Lab 7: Practice with Dictionaries, Objects, and HTML

Goals

After the lab, you should be proficient at

  1. solving problems using dictionaries
  2. solving problems using classes and objects from a library

Linux

As usual, create a directory for the programs and output you develop in this lab.

You will need to copy all the files from /home/courses/cs111/handouts/lab7 into the directory you created.

Objective: Programming in Python

Some Reference Materials:

We'll practice writing several Python programs, each in their own text file. Name the files lab7.1.py through lab7.4.py.

Your programs will be graded on correctness, style, efficiency, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class. Your code should be readable and your output should be useful and well-formatted.

After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab7.x.out, where x is the problem number.

  1. (10) Using a dictionary object, create a program that maps a letter to an example word that starts with that letter. You must have at least three entries in your dictionary. Then, print out the dictionary so that it looks similar to a children's book and the keys are printed in alphabetical order. Example output looks like:
    f is for fiddle
    g is for goose
    z is for zoo
    
  2. (25) Write a program that reads in a text file, counts how many times a word occurs in the text file, and writes out a summary output file containing the words (in alphabetical order) and the number of times each word occurs in the format:
    <count> <word>
    

    The format of the output file may be different from what you expected. The reason that it's in this format is so that we can use a Unix utility to view the data in a different way.

    Note that the punctuation (except for apostrophes) has been removed from the files, so you don't need to worry about that. However, you should count, for example, the words "the" and "The" as the same word.

    This is a larger program. You will have to break it into smaller pieces, solve (and test) a piece, and then move on to the next piece.

    There are three files, copied from the handouts/lab07 directory, for you to test your program on. The files have the ".txt" extension.

    To view the output files you've created, use the commands more or cat. Use them as
    more <summary_file>

    You should name the summary files with different names to distinguish the files, e.g., huck_count.dat. (You can do that either in your program or using Linux commands.)

    For each of your summary files, run the command:

    sort -n <summary_file>
    
    and report the top 5 most frequently used words in each file in comments in your program. Any surprises in the results?
  3. (35) Create a program that draws "something significant", such as a scene, a house, or a face, using the graphics library. Here are some guidelines to follow:

    Screen Capture:

    You've saved the image!

    Some previously created images to inspire you:

  4. (20) Add some sort of animation to the picture you created above. For example, you could make the entire face move around the window or you could have one feature of the face move (such as a blinking eye).

Objective: Creating a New Web Page

It's time to revisit our web pages. (You knew we'd get back to this sooner or later!)
  1. Go into your public_html directory.
  2. Copy your index.html file into a file called lab7.html (in the public_html directory).
  3. Copy the screen capture image from your lab into your public_html directory.
  4. Open lab7.html in jEdit.
  5. Modify the Lab 7 web page to have an appropriate, title, header, and information.
  6. Modify your Lab 7 web page to display the image you created.
  7. Modify your index.html page to link to your Lab 7 web page.

Finishing up: What to turn in for this lab

  1. IDLE and jEdit may create backup files with the "~" extension. Delete these files from your lab directory to save paper when you print.
  2. Copy your lab7 directory into the turnin directory. (Review the UNIX handout if you don't remember how to do that.)
  3. Before printing, move the graphics.py, graphics.pyc (actually, this one can be deleted rather than moved), original ".txt" files, the summary files, and your screenshot out of your labs/lab7 directory; otherwise, the print out will be long and screwed up. You can move those files back into your lab7 directory after you've printed. In other words, you should only have the .py files you wrote and the .out files you created.

    I changed this a bit from the original instructions. I can look at your code and the output files in your turnin directory to make sure that they're in the correct format. Make sure not to move those files out of your directory until after you've copied them into your turnin directory.

  4. Use the printLab.sh command to create a file to print out. You should probably print from the labs directory.

    Print the file using the lpr command introduced in the first lab.

Labs are due at the beginning of Friday's class. You should hand in the printed copy at the beginning of class, and the electronic version should be in the turnin directory before 2:25 p.m. on Friday.

Ask well before the deadline if you need help turning in your assignment!

Grading (100 pts)