EOS; include("../../header.php"); ?>

Programming Assignment 7


  1. (25 points) Problem 10.3 of the book. Count occurrence of numbers. Write a program all in a main method that reads some integers between 1 and 100 and counts the occurrences of each.
  2. (25 points) Problem 10.9 of the book. Statistics: compute deviation. Write a method to compute the standard deviation of a list of numbers using the following equations: $$mean = \frac{\Sigma_{i=1}^n x_i}{n} = \frac{x_1 + x_2 + \ldots + x_n}{n}, \qquad deviation = \sqrt{\frac{\Sigma_{i=1}^n(x_i - mean)^2}{n-1}} $$ To compute the standard deviation with these formulas, you have to store the individual numbers using a list, so that they can be used after the mean is obtained.

    In a separate file (statistics.py), write the following functions for the equations:

    # Compute the standard deviation of values
    def deviation(x):

    # Compute the mean of a list of values
    def mean(x):

    Write a mean method to prompt the user to enter a list of numbers and display a formatted mean (2 decimals) and standard deviation (5 decimals).
  3. (25 points) Problem 10.26 of the book. Merge two sorted lists. Write the following function that merges two sorted lists into a new sorted list.

    def merge(list1, list2)

    Implement the function so that it takes len(list1) + len(list2) comparisons. Write a main method to test your function that prompts the user for two sorted lists and displays the merged list.

    The original lists should not be modified. Additionally, You must do this with your own algorithm. For example, you cannot simply use Python's build in functionality to append the lists together and sort them.
  4. (25 points) Problem 13.2 of the book. Count characters, words, and lines in a file. Write a program (main function only) that will count the number of characters, words, and lines in a file. Words are separated by a white space character. Your program should prompt the user to enter a filename.
  5. Bonus. (10 points) Problem 13.8 and 13.9 of the book. Cryptography. Write a file (cryptography.py) with two functions (def encrypt(inFilename, outFilename) and def decrypt(inFilename, outFilename)) that can facilitate encrypting and decrypting files. The encryption scheme will add 5 to every byte, and the decryptions scheme reverses this process.

    Write a main function to allow the user to provide three files to test your process, an original file, output for the encrypted file, and output file for the decryption of the encrypted file. The contents of the original file and decrypted file should be identical.