Assignment 9
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Assignment 9
INSTRUCTIONS
Overview. For this assignment you will be writing 3 scripts which should be saved independently as their own .py files. When you're finished you should submit your programs to the Assignment #9 category in Brightspace.
File Naming. Your solution to the first problem should be named as follows: LastNameFirstName_Assign9_Problem1.py
File Instructions. At the top of your assignment, include your name, the assignment number, the problem number, the date, and the name of your program at the top of your file as comments. If you worked with another student, you should also include their name.
It should look like this:
"""
Assignment: 9
Problem: 1
Partner: Karin Kiontke
"""
Each problem will give detailed instructions on how data should be stored and manipulated. Also comment your source code and describe your code to someone who may be viewing it for the first time.
Each problem will give detailed instructions on how data should be stored and manipulated. For full credit,
● Output formatting should match the examples exactly.
● Comment your source code to briefly explain each block of statements.
● Import variables and functions where appropriate.
● Code should be concise.
● Code should be modular and broken into functions where appropriate.
● Include function docstrings.
Groupwork. You may discuss problems with a partner, but each student must write and submit their own code. Please credit any discussion partners in at the top of the assignment. If you worked alone, explicitly state so. Failure to acknowledge partners or state that you worked alone will result in a 0 grade for this assignment.
Early submission policy. Submit all or part of your assignment by the early deadline; feedback and a preliminary grade for early submissions will be published by the end of the weekend. You can submit revisions by the submission deadline for a final grade. Any files received after submission deadline will have grace days automatically deducted.
PROBLEM 1: Reading data from external files (3 points)
During the American Revolutionary War, the Culper Spy Ring operated out of New York to gather information about British activities in occupied territories. The spies used a code book, replacing some text with numbers that represented hidden messages . The file culper_cipher.csv is a digital codebook that stores both the numbers (keys) and their associated meanings (values) that the spies used.
Write a program that asks the user to input some text. The program will first scan through user entry, replace any suspected keys with their values, and print a “decrypted” version of the text. If the number is not found in the codebook, then keep the original number.
* There may be some encoding issues that corrupt the first line of the file. You can replace the information before the first comma with the string “1”.
EXAMPLE 1
Enter original message:
724 returned from 727 last night.
Decrypted message:
Austin Roe returned from New York last night.
EXAMPLE 2
Enter original message: My 151 hath put it out of my power to make any 322 about the 178 in these 467.
Decrypted message:
My disorder hath put it out of my power to make any inquiry about the enemy in these opportunity.
PROBLEM 2: Writing data to external files (3 points)
(Substitute your last name where LastName appears in the file names below.)
Write a program that prompts the user to enter phone numbers. The user will enter numbers until they enter in Q, prompting the program to end. The user entries will be stored in two unique files: (1) LastName_user_entries.txt and (2)
LastName_formatted_numbers.txt.
For the first file, record every user entry.
For the second file, only add phone numbers. Although the user can enter ten-digit numbers in any format, the phone numbers written out to LastName_formatted_numbers.txt must be formatted to (212)855-6962.
In both files, each string or formatted phone number should appear on a new line. For this problem, both output files will be in the same directory as your program and file path does not need to be specified. You do not need to include output files in your assignment submission.
PROBLEM 3: Accessing web data (4 points)
In Python, access and download the plain text version of the Universal Declaration of Human Rights (UDHR) from the following link:
http://unicode.org/udhr/d/udhr_eng.txt
After storing all UTF-8 decoded data in a list, delete the first six lines (header), remove any numbers and punctuation, and strip excess spaces . Now ask the user to enter a word. Lookup the word and print the number of times it appears in the UDHR.
For this script, capitalization should not matter, so “Truth” and “truth” are the same for the both word counter and user input.
Below are a few sample runnings of the program. Underlines indicate user input.
Example 1
Enter word to lookup: the
The appears 121 times in the UDHR.
Enter word to lookup: universal
Universal appears 5 times in the UDHR.
Enter word to lookup: declaration
Declaration appears 7 times in the UDHR.
Enter word to lookup: of
Of appears 91 times in the UDHR.
Enter word to lookup: human
Human appears 13 times in the UDHR.
Enter word to lookup: rights
Rights appears 22 times in the UDHR.
Enter word to lookup: Q
Example 2
Enter word to lookup: LIFE
Life appears 3 times in the UDHR.
Enter word to lookup: LIBERTY
Liberty appears 1 time in the UDHR.
Enter word to lookup: PURSUIT
Pursuit not in the UDHR.
Enter word to lookup: OF
Of appears 91 times in the UDHR.
Enter word to lookup: HAPPINESS
Happiness not in the UDHR.
Enter word to lookup: Q
2022-11-28