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.
    • Name the file and program ch10_pr03.py.
    • Example execution (python3 ch10_pr03.py on MAC and py -3 ch10_pr03.py on Windows) user provides input (red):
      Enter integers between 1 and 100: 2 5 6 5 4 3 23 43 2
      2 occurs 2 times
      3 occurs 1 time
      4 occurs 1 time
      5 occurs 2 times
      6 occurs 1 time
      23 occurs 1 time
      43 occurs 1 time
  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).
    • Name the files and program statistics.py and ch10_pr09.py.
    • Example execution (python3 ch10_pr09.py on MAC and py -3 ch10_pr09.py on Windows) user provides input (red):
      Enter numbers: 1.9 2.5 3.7 2 1 6 3 4 5 2
      The mean is 3.11
      The standard deviation is 1.55738
  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.
    • Name the file and program ch10_pr26.py.
    • Example execution (python3 ch10_pr26.py on MAC and py -3 ch10_pr26.py on Windows) user provides input (red):
      Enter list1: 1 5 16 61 111
      Enter list2: 2 4 5 6
      The merged list is 1 2 4 5 5 6 16 61 111
  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.
    • Name the file and program ch13_pr02.py.
    • Example execution (python3 ch13_pr02.py on MAC and py -3 ch13_pr02.py on Windows) user provides input (red), input file can be downloaded/seen here:
      Enter a filename: diablo_story.txt
      1528 characters
      318 words
      32 lines
  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.
    • Name the files and program cryptography.py and ch13_pr08_09.py.
    • Example execution (python3 ch13_pr08_09.py on MAC and py -3 ch13_pr08_09.py on Windows) user provides input (red), input file can be downloaded/seen here:
      Enter the original filename: quick_brown_fox.txt
      Enter the encrypted filename: encrypted.txt
      Enter the decrypted filename: decrypted.txt
      Done
      output file contents can be seen here (encryption) and here (decryption)


General Instructions, Turning in assignments, and Grading

General Instructions

Turn in Instructions

Each assignment will be turned in through GitHub classroom. Please find the link to create a repository at the top of this page, or through this link. Robot problems must be demonstrated by 5pm and assignments must be submitted to GitHub by 11:59pm of the due date. I do not accept any late assignments.

Additionally, robotics problems will need to be demonstrated to me. This must be demonstrated to me by 5pm on the due date.

Points