Programming Assignment 7
-
(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 andpy -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
- Name the file and program
-
(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
andch10_pr09.py
. - Example execution
(
python3 ch10_pr09.py
on MAC andpy -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
- Name the files and program
-
(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 takeslen(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 andpy -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
- Name the file and program
-
(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 andpy -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
- Name the file and program
-
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)
anddef decrypt(inFilename, outFilename)
) that can facilitate encrypting and decrypting files. The encryption scheme will add5
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
andch13_pr08_09.py
. - Example execution
(
python3 ch13_pr08_09.py
on MAC andpy -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
- Name the files and program
General Instructions, Turning in assignments, and Grading
General Instructions
- Name each file and program as listed in the instructions.
- The top of each program should have a comment block where the first line
is your name and following lines are a description of your program.
# Name: Jory Denny
# This program debates Batman vs Superman!
# References:
# - Ref 1. - Any program solution that defines its own function or class must have a
main
function and properly specified entry point into the program, e.g.:
def main():
# Do something
if __name__ == '__main__':
main() - Use proper coding style (described more in Grading below)
- While I support extra research, use of online materials, and collaboration with other students, please ensure the work is your own and you understand all portions of the work you turn in.
- Follow turn-in instructions precisely.
- Failure to complete any of these steps will result in a significant loss of points.
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.
- Soft copy (Online submission)
- Accept the invitation to the classroom assignment, which creates your repository on GitHub.
- Clone this repository, which includes some starting files.
- Add assignment files (stage, commit, push).
- Modify the Coverpage.txt file to provide name, sources, signature of following the honor code, etc. Be sure to stage, commit, and push these changes as well. If you do not fill out the coverpage, I will not grade the assignment.
- After the due date, I will clone your repository and add a grade and comments as necessary. After which you can pull these changes for your records.
Additionally, robotics problems will need to be demonstrated to me. This must be demonstrated to me by 5pm on the due date.
Points
- Each assignment is graded out of 100 points (not including bonus).
- Criteria and point distribution
- If the code is not named precisely or does not execute correctly, -50% on a problem.
- Following instructions and algorithm used to solve the problem, 25% on a problem. Following instructions is extremely important in computer science, train yourself to think like a computer. There are many ways to solve a problem, some may be better or worse than others.
- Stylistic elements of written code,
25% of a problem. Style includes (but is not
limited to):
- Every class, method, and function must be documented with docstrings describing its purpose, formal arguments, and return value.
- Control flow should be documented with intent and purpose of code
- Naming should be descriptive and consistent
- Indenting properly
- Consistent spacing
- Avoiding code duplication
- While I support extra research, use of online materials, and collaboration with other students, please ensure the work is your own and you understand all portions of the work you turn in. If I suspect excessive use of online materials, I will invite you to walk me through your solution. If you are not able to explain the work sufficiently, I will not give credit for that problem.
- If there are any discrepancies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).