Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this task, you are required to define a class for analysing the number of occ

ID: 3720113 • Letter: I

Question

In this task, you are required to define a class for analysing the number of occurrences for each of the letters (i.e. ‘A’ to ‘Z) and numerals (i.e. ‘0’ to ‘9’) from the decoded sequences. This class should have one instance variable which is a dictionary structure that is used for keeping track of the number of occurrences for each of the letters and numerals decoded by the Morse Code decoder in Task 1.

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

• __init__(self):
This is the constructor that is required for creating instances of this class. You should

define and initialise the dictionary structure for characters (i.e. the instance variable) in the constructor.

• __str__(self):
Re-define this method to present the number of occurrences for each of the letters and numerals in a readable format. You should return a formatted string in this method.

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)

Explanation / Answer

I have used python 3.6 version.
The decoded sequence is considered as a list of characters.

Python3.6 Code

#!/usr/bin/python3.6

class analyser():

def __init__(self):
"Intialization function"
self._charDict = {} ##instance variable intialized as dictionary.

def __str__(self):
Str = ""
for Char, Count in self._charDict.items():
Str = Str + "char '{0}' --- {1} ".format(Char, Count)
return Str

def analyse_characters(self, decoded_sequence):
"This function update the charachter count into the dictionary from the given list of chaaracters"
for Char in decoded_sequence:
if Char not in self._charDict:
self._charDict[Char] = 1
else :
self._charDict[Char] += 1


Anal = analyser()
Anal.analyse_characters(['a', 'b', 'a'])
print(Anal),

--------------------------------------------

Output shown after running this program :

$)python main.py
char 'a' --- 2
char 'b' --- 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote