Question

Using the template code provided in the braille translator.py file as a starting point, complete functions enocode and decodeThe Decode Function Complete the function called decode that takes the name of a file containing the Braille text as an input

0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: You have not given instructions for encode, so I have not done it. Moreover the example given for cat is incorrect. So, I have taken other example."

Code is here and screenshots are provided below for help:

braille_table={"a":[[1,0],[0,0],[0,0]],
               "b":[[1,0],[1,0],[0,0]],
               "c":[[1,1],[0,0],[0,0]],
               "d":[[1,1],[0,1],[0,0]],
               "e":[[1,0],[0,1],[0,0]],
               "f":[[1,1],[1,0],[0,0]],
               "g":[[1,1],[1,1],[0,0]],
               "h":[[1,0],[1,1],[0,0]],
               "i":[[0,1],[1,0],[0,0]],
               "j":[[0,1],[1,1],[0,0]],
               "k":[[1,0],[0,0],[1,0]],
               "l":[[1,0],[1,0],[1,0]],
               "m":[[1,1],[0,0],[1,0]],
               "n":[[1,1],[0,1],[1,0]],
               "o":[[1,0],[0,1],[1,0]],
               "p":[[1,1],[1,0],[1,0]],
               "q":[[1,1],[1,1],[1,0]],
               "r":[[1,0],[1,1],[1,0]],
               "s":[[0,1],[1,0],[1,0]],
               "t":[[0,1],[1,1],[1,0]],
               "u":[[1,0],[0,0],[1,1]],
               "v":[[1,0],[1,0],[1,1]],
               "w":[[0,1],[1,1],[0,1]],
               "x":[[1,1],[0,0],[1,1]],
               "y":[[1,1],[0,1],[1,1]],
               "z":[[1,0],[0,1],[1,1]]}
             
def decode(file_name):
    f1=open(file_name,"r")
    Lines=f1.readlines()
    word=""
    for line in Lines:
        l1=[]
        l2=[]
        l3=[]
        l4=[]
        for i in range(0,2):
            l1.append(int(line[i]))
        for i in range(2,4):
            l2.append(int(line[i]))
        for i in range(4,6):
            l3.append(int(line[i]))
        l4=[l1,l2,l3]
        for letter,key in braille_table.items():
            if key==l4:
                word+=letter
    return word


file_name=input("Enter file name: ")
plain_text=decode(file_name)
print(plain_text)

screenshots of code with comments:braille_table 11 #Dictionary for braille conversion {a:[[1,0],[0,0],[0,0]], 6:[[1,0],[1,0],[0,0]], C:[[1,1],[0,0],[0,0]

decode(file_name): #Takes the name of file containing matrix of braille of word as input f1=open(file_name, r) #Open file i

text file used for exampleOpen text.txt -Desktop Save 00 100000 101000 110000

output of code

Enter file name: text.txt abc

Please give your feedback

Add a comment
Know the answer?
Add Answer to:
Using the template code provided in the braille translator.py file as a starting point, complete functions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

  • Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary...

    Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method to...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a doc...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • In this part, you will complete the code to solve a maze.

    - Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...

  • In a new file located in the same package as the class Main, create a public...

    In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...

  • CSC 142 Music Player You will complete this project by implementing one class. Afterwards, your program...

    CSC 142 Music Player You will complete this project by implementing one class. Afterwards, your program will play music from a text file. Objectives Working with lists Background This project addresses playing music. A song consists of notes, each of which has a length (duration) and pitch. The pitch of a note is described with a letter ranging from A to G.   7 notes is not enough to play very interesting music, so there are multiple octaves; after we reach...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT