Question
Write a PYTHON code to convert 'a word' to a horizontal matrix and then convert the horizontal matrix to 'word'. 1) Create an encode() function
Write a PYTHON code to convert 'a word' to a horizontal matrix and then convert the horizontal matrix to 'word'.
1) Create an encode() function to that takes a word as input and prints a matrix representation
Each letter in the word can be represented as a 3 2 matrix (convert each letter from dict format to horizontal matrix)
In case of multiple letters, the encode() function must represent the word by simply concatenating the matrices horizontally.
For example:
"a": [[1, 1], [0, 0], [0, 0]]
"b": [[1, 1], [1, 0], [0, 0]]
"c": [[1, 0], [0, 0], [0, 0]]
If the input is 'abc', the output will be:
2) Create an translate() function to that takes name of a txt file containing the matrix text as input and prints a word.
For examples, read the matrix in the data.txt and then translate it to a word using the translate_table() above.
Input: data.txt containing matrix below:
Output: abc
For the simplification, data.txt file will only contain 1 word and all lowercase letters.
1 - def encode_table (): 2 3- dict = { 4 "a": [[1, 1], [0, 0], [0, 0]], 5 "b": [[1, 1], [1, 0], [0, 0]], 6 "C": [[1, 0], [0, 0], [0, 0]], 7 "d": [[1, 0], [0, 1], [0, 0]], 8 "e": [[1, 1], [0, 1], [0, 0]], 9 "f": [[1, 0], [1, 0], [0, 0]] 10 } 11 12 return dict w 00 OU A 12 1 1 1 1 1 0 0 0 1 0 0 0 OOOOOO albc 1 1 1 1 1 0 0 0 1 0 0 0 eeeeee 1 - def translate_table (): 2 3- translate = { 4 "110000": "a", 5 "111000": "b", 6 "100000": "C", 7 "100100": "d", 8 "110100": "e", 9 "101000": "f" 10 } 11 12 return translate vou AWN 1 1 1 1 1 0 0 0 1 0 0 0 eeeeeeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started