In n Python Code:  * Using the MorseCode.csv file, read the file and process the comma separated variables.  See the Elements.py file for an example of reading a CSV file.  File excerpt:     A,.-     B,-...     C,-.-.     D,-..     E,. * Design a Morse Code class to contain ASCII and Morse Code characters.  For example, the Morse Code for the letter 'C' is "-.-.". * Add the Dunders to the Morse Code class to support:  initialization, iterating, printing, searching, sorting. * Design a Morse Code collection class to contain the 39 Morse Code characters listed in the CSV file.  The Morse Code collection class contains an internal Dictionary for storing each individual Morse Code characters. * Demonstrate your Dunders work correctly for initialization, iterating, printing, searching and sorting. Morse Codes: E . T - A .- I .. M -- N -. D -.. G --. K -.- O --- R .-. S ... U ..- W .-- B -... C -.-. F ..-. H .... J .--- L .-.. P .--. Q --.- V ...- X -..- Y -.-- Z --.. 0 ----- 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. Elements code: class Element : def __init__(self,nu,ab,na) : # constructor self.number = int(nu) self.abbrev = ab self.name = na def __str__(self): # string conversion operator return str(self.name + '\t' + self.abbrev + '\t' + str(self.number)) def __lt__(self,right): # less-than operator print(str(self.number) + "__lt__" + str(right.number)) return self.number < right.number def __eq__(self,right): # equality operator print(str(self.number) + "__eq__" + str(right.number)) return self.number == right.number class PeriodicList : def __init__(self): #constructor self.table = [] def __getitem__(self,index): print("__getitem__ index = ",index) return self.table[index] def __setitem__(self,index,value): print("__setitem__ index = ",index,value) self.table[index] = value def __str__(self) : stable = "" for i in range(0,len(self.table)): stable = stable + str(self.table[i]) return stable def Sort(self): self.table.sort() def Reader(self,csvfile): csv = open(csvfile) for line in csv : rline = line.rstrip() cline = rline.split(',') e = Element(int(cline[0]),cline[1],cline[2]) self.table.append(e) def main(): pt = PeriodicList() pt.Reader('ptable.csv') print(pt) # sorted by name pt.Sort() print(pt) # sorted by number efind = Element(80,"Hg","Mercury") if efind in pt: print("Found: ",efind) if __name__=="__main__": main() * This requires 2 classes not 1 Class

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In n Python Code: 

* Using the MorseCode.csv file, read the file and process the comma separated variables.  See the Elements.py file for an example of reading a CSV file.  File excerpt:

    A,.-
    B,-...
    C,-.-.
    D,-..
    E,.

* Design a Morse Code class to contain ASCII and Morse Code characters.  For example, the Morse Code for the letter 'C' is "-.-.".

* Add the Dunders to the Morse Code class to support:  initialization, iterating, printing, searching, sorting.

* Design a Morse Code collection class to contain the 39 Morse Code characters listed in the CSV file.  The Morse Code collection class contains an internal Dictionary for storing each individual Morse Code characters.

* Demonstrate your Dunders work correctly for initialization, iterating, printing, searching and sorting.

Morse Codes:

E .
T -
A .-
I ..
M --
N -.
D -..
G --.
K -.-
O ---
R .-.
S ...
U ..-
W .--
B -...
C -.-.
F ..-.
H ....
J .---
L .-..
P .--.
Q --.-
V ...-
X -..-
Y -.--
Z --..
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.

Elements code:

class Element :
def __init__(self,nu,ab,na) : # constructor
self.number = int(nu)
self.abbrev = ab
self.name = na
def __str__(self): # string conversion operator
return str(self.name + '\t' + self.abbrev + '\t' + str(self.number))
def __lt__(self,right): # less-than operator
print(str(self.number) + "__lt__" + str(right.number))
return self.number < right.number
def __eq__(self,right): # equality operator
print(str(self.number) + "__eq__" + str(right.number))
return self.number == right.number

class PeriodicList :
def __init__(self): #constructor
self.table = []
def __getitem__(self,index):
print("__getitem__ index = ",index)
return self.table[index]
def __setitem__(self,index,value):
print("__setitem__ index = ",index,value)
self.table[index] = value
def __str__(self) :
stable = ""
for i in range(0,len(self.table)):
stable = stable + str(self.table[i])
return stable
def Sort(self):
self.table.sort()
def Reader(self,csvfile):
csv = open(csvfile)
for line in csv :
rline = line.rstrip()
cline = rline.split(',')
e = Element(int(cline[0]),cline[1],cline[2])
self.table.append(e)

def main():
pt = PeriodicList()
pt.Reader('ptable.csv')
print(pt) # sorted by name
pt.Sort()
print(pt) # sorted by number
efind = Element(80,"Hg","Mercury")
if efind in pt:
print("Found: ",efind)

if __name__=="__main__":
main()

* This requires 2 classes not 1 Class

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY