CS 30 Homework 3

Due by class time Wednesday, February 15

If you wish, you may work with a partner on this assignment.

Reading

Practice Exercises (Optional)

These will give you extra practice with Python, but you do not need to turn them in. I would strongly recommend doing them if you have never programmed before.

Problems to Turn In

The following problems should be turned in. Using IDLE, create a new file named assign3.py and put all of your program definitions in this file. That way, you can load them all into Python at once for testing by simply pressing the [F5] key.

  1. The file elementsData.txt contains information about chemical elements. Each line corresponds to a single element, and consists of the following information:

    Write a program called elements() that reads in the information from the file and prints it out in a nicely-formatted table, exactly as shown below:

                   Element (symbol)    Atomic Weight
              --------------------------------------
                1. Hydrogen (H)            1.008
                2. Helium (He)             4.003
                3. Lithium (Li)            6.939
                4. Beryllium (Be)          9.012
                5. Boron (B)              10.811
                6. Carbon (C)             12.011
                7. Nitrogen (N)           14.007
                8. Oxygen (O)             15.999
                9. Fluorine (F)           18.998
               10. Neon (Ne)              20.183
    
  2. Finish problems 3, 4, and 5 from Lab 4. Name your programs as follows:

  3. Study the bubbles.py example we developed in lab. Using a for-loop in conjunction with the move operation for graphics objects and the time.sleep function, create some kind of animated image that randomly wanders around the graphics window, in a relatively smooth fashion. Can you make it wander around forever? Call your program wander().

EXTRA CREDIT

  1. Do Problem 12 on page 162. Call your program barchart(). Here is a file you can use for testing. The output should look similar to the bar chart shown on page 162.

  2. Do Problem 13 on page 163. Call your program histogram(). Here is a file you can use for testing. The output should look similar to the histogram shown on page 163.

Turning in Your Homework

Put all of your function definitions into a single Python file called assign3.py and include your name in a comment (i.e. a line beginning with #) at the top of the file. Submit this file electronically by running the /common/cs/submit/cs30-submit script from any Pomona Linux machine. Be sure to run this command from the directory containing your file.

If you have questions about anything, don't hesitate to ask!