Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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]]

image text in transcribed

If the input is 'abc', the output will be:

image text in transcribed

2) Create an translate() function to that takes name of a txt file containing the matrix text as input and prints a word.

image text in transcribed

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:

image text in transcribed

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 eeeeee

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Identify the functional group in cach of the following compounds

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago