Question: Task 1: Building a class for Morse Code decoder In the first task, you are required to define a class that serves as the Morse

Task 1: Building a class for Morse Code decoder

In the first task, you are required to define a class that serves as the Morse Code decoder. This class should have one instance variable which is a dictionary structure that represents each of the Morse Code characters (presented in Table 1) as a string sequence of binary digits (0 and 1). This decoder class is used for decoding any Morse Code sequences.

The implementation of this decoder class should include the following three methods:

__init__(self): This is the constructor that is required for creating decoder instances. You should define and initialise the dictionary structure for the Morse Code representation (i.e. the instance variable) in the constructor.

__str__(self): Re-define this method to present the Morse code representation table (i.e. the dictionary structure) in a readable format. You should return a formatted string in this method.

decode(self, morse_code_sequence): This is the method that performs the decoding process. This method should accept a Morse Code sequence as the argument, and attempt to decode it. The decoded message should be returned as a string. (If you encountered an invalid character while decoding, return an error message instead of the partially decoded message.)

Note: The Morse Code sequence should terminate with one of the three punctuation characters, i.e. the period .; the comma ,; and the question mark ?.Task 1: Building a class for Morse Code decoder In the first

You should not consider the punctuation characters in this task as they will be handled in another task

Table 1 defines the set of Morse Code representation used in this assignment Character Morse Code Character Morse Code Character Morse Code 10 0 01 1000 1010 100 0110 1101 010 00111 00011 00001 0010 110 10000 11000 11100 001 0001 011 1001 1011 1100 0111 101 0100 010101 110011 001100 Table 1: Morse Code representation for this assignment (letters, numerals, and punctuations)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!