Assignment:
Modify the Python program by adding the create_dictionary function. The parameter file_name
is the name of the csv file that contains several lines of ASCII encodings. The format of this file
is described in the link above. The function should return a dictionary where the keys are
characters and the values are the 8 bit representations. Note: use the characters for comma, quote,
and space characters, instead of the words comma, quote, and space.
Add the translate function. The parameter sentence consists of a number of characters. The
parameter dictionary is the dictionary returned 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, the
text should be a binary string (zeros and ones only) with each 8 bit ascii code appearing one after
the other. (see sample transcripts)
If a character does not appear in the dictionary, the string "\nUNDEFINED\n" should appear
instead of an 8 bit representation.
When the program is run, it should produce the following three output files: output-1.txt, output-
2.txt and output-3.txt.
Grading:
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 comma, quote, and space.
3 points - When your program is tested with different values for the variable sentence, all
characters that exist in the dictionary are translated correctly.
1 point - When your program is tested with different values for the variable sentence, characters
that do NOT exist in the dictionary are translated correctly to the word UNDEFINED on a line of
its own.
1 point - The format of any output files created match the format of the sample output files
exactly. def create_dictionary(f): \# f is the filename; rename the parameter as you wish pass \#
open the file for reading and assign to a file handle variable* \# make a dictionary variable -- it
can be empty to start with \# use the file handle variable step through each line doing this.." \#
make the line into a list, splitting it up at the commas \# optional: temporarily try printing it out.
What you expected? \# assign the binary number to a variable as a string \# optional: temporarily
try printing it out. What you expected? \# assign the character to a variable as a string \#
optional: temporarily try printing it out. What you expected? \# use the two new variables to add
an entry to the dictionary \# optional: temporarily try printing it out. What you expected? \#
Note: you will want the comma, space, and quote mark keys to be those actual characters.". \#
"make sure that gets handled at some point before returning the dictionary \# *don't forget to
close the file \# return the dictionary to where it was called from def translate(s, d, f): \# rename
the parameters as you wish pass
010000010010000001101100011.
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
AssignmentModify the Python program by adding the create_dictiona.pdf
1. Assignment:
Modify the Python program by adding the create_dictionary function. The parameter file_name
is the name of the csv file that contains several lines of ASCII encodings. The format of this file
is described in the link above. The function should return a dictionary where the keys are
characters and the values are the 8 bit representations. Note: use the characters for comma, quote,
and space characters, instead of the words comma, quote, and space.
Add the translate function. The parameter sentence consists of a number of characters. The
parameter dictionary is the dictionary returned 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, the
text should be a binary string (zeros and ones only) with each 8 bit ascii code appearing one after
the other. (see sample transcripts)
If a character does not appear in the dictionary, the string "nUNDEFINEDn" should appear
instead of an 8 bit representation.
When the program is run, it should produce the following three output files: output-1.txt, output-
2.txt and output-3.txt.
Grading:
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 comma, quote, and space.
3 points - When your program is tested with different values for the variable sentence, all
characters that exist in the dictionary are translated correctly.
1 point - When your program is tested with different values for the variable sentence, characters
that do NOT exist in the dictionary are translated correctly to the word UNDEFINED on a line of
its own.
1 point - The format of any output files created match the format of the sample output files
exactly. def create_dictionary(f): # f is the filename; rename the parameter as you wish pass #
open the file for reading and assign to a file handle variable* # make a dictionary variable -- it
can be empty to start with # use the file handle variable step through each line doing this.." #
make the line into a list, splitting it up at the commas # optional: temporarily try printing it out.
What you expected? # assign the binary number to a variable as a string # optional: temporarily
try printing it out. What you expected? # assign the character to a variable as a string #
optional: temporarily try printing it out. What you expected? # use the two new variables to add
an entry to the dictionary # optional: temporarily try printing it out. What you expected? #
Note: you will want the comma, space, and quote mark keys to be those actual characters.". #
2. "make sure that gets handled at some point before returning the dictionary # *don't forget to
close the file # return the dictionary to where it was called from def translate(s, d, f): # rename
the parameters as you wish pass
01000001001000000110110001101111011011100110011100100000011101000110100101101
101011001010010000001100
00101100111011011100100000011010010110111000100000011000010010000001100111011
00001011011000110000101
11100001111001001000000110011001100001011100100010110000100000011001100110000
101110010001000000110000 1011101110110000101111001001011100010111000101110
O0100110101101111011011100111010001100001011011100110000100100000010100110111
0100011000010111010001100
10100100000010101010110111001101001011101100110010101110010011100110110100101
110100011110010010000000
10100000110100001100000011011000101001001000000011001001110010011010000101101
00110000001100100011000 100110001
NDEFINED
O1010100011100100111010101100101001000000110011001110010011010010110010101101
110011001000111001100100
00011100110111010001100001011000100010000001110010110111011101010010000001101
001011011100010000001
10100011010000110010100100000011001100111001001101111011011100111010000101110
NDEFINED 0100000 NDEFINED 101011101101001011011000110010001100101