Lab 8: Dictionaries
Logistics
- Due: Tuesday, October 17th no later than 11:59 p.m..
- Partner Information: Complete this assignment individually
or with a partner.
- Submission Instructions (Working Alone): Upload your solution, renamed to
YourFirstName-YourLastName-Lab8.py to the BrightSpace
Lab 8 Dropbox.
- Submission Instructions (Working With a Partner):
Upload your solution, renamed to
YourFirstName-YourLastName-PartnerFirstName-PartnerLastName-Lab8.py
to the BrightSpace Lab 8 Dropbox.
- Deadline Reminder: Once this deadline passes, BrightSpace will no
longer accept your Python submission and you will no longer
be able to earn credit. Thus, if you are not able to fully complete
the assignment, submit whatever you have before the deadline so that
partial credit can be earned.
Learning Outcome
- Gain experience with dictionaries.
Preliminaries
- ASCII (American Standard Code for Information Interchange)
is a code developed in 1963 that is used to represent
characters (such as the character 'X') with decimal numbers
that range from 0 to 127. Here is the
ASCII table.
- Download lab8.py, rename it according to
the instructions above, and make sure you understand it.
- Download input file ascii-codes.txt
to the same directory where you downloaded lab8.py.
The first line in this comma-separated-values file shows the three
pieces of information that will appear on each subsequent line:
a Character (e.g. A), followed by a
Code that is the corresponding ASCII decimal code (e.g. 65),
followed by a Description of the Character (e.g. Uppercase A).
In general, the character will be of length 1
such as the character X. However,
there are two exceptions: " " is represented by space
and "," is represented by comma.
Assignment
- Take the program above and modify it by adding the create_dictionary
function. The parameter file_name is the name of a file
that contains information about ASCII encodings.
The format of this file is described in the bullet above.
The function should return a dictionary where
the keys are the characters and the values are the decimal
encodings. Note: use " " and "," as keys instead of space
and comma.
- Take the program above and modify it by adding the translate
function. The parameter sentence consists of an unknown number
of characters. The parameter dictionary is the dictionary that was
created by the create_dictionary function. The parameter
file_name is the name of the output file where all output should
be sent. In the output file, each character in sentence should
appear on its own line, followed by a space, followed by its decimal
representation. You may assume that all characters in a sentence
will appear in the dictionary.
- When the program is run,
it should produce the following three output files:
output-1.txt,
output-2.txt and
output-3.txt.
Grading - 10 points
- 2 points - The create_dictionary function returns a dictionary
that contains the correct binary code for each character of length one.
- 1 point - The create_dictionary function returns a dictionary
that contains the correct binary code for " " and ",".
- 5 points - When your program is tested with different values for
the variable sentence, characters that exist in the dictionary
are translated correctly. For each unique character that is translated
incorrectly, one point will be deducted.
- 1 point - The format of any output files created
match the format of the sample output files exactly.
- 1 point - In a comment at the top of the python file that you submit,
explain why the comma character and the space
character are treated differently in ascii-codes.txt.
If Time Remains
- Work on Program 4 with your Program 4 partner,
seeking feedback as necessary. As a reminder, Program 4
requires working with one classmate who is in your
lab section. If you haven't already identified that
partner, ask your lab TA to help you.