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

Provide a class Letter for authoring a simple letter. In the constructor, supply

ID: 3713223 • Letter: P

Question

Provide a class Letter for authoring a simple letter. In the constructor, supply the names of the sender and the recipient: def _init (self, letterFrom, letterTo) Supply a method def addLine (self, line) to add a line of text to the body of the letter Supply a method def getText(self) that returns the entire text of the letter. The letter has the form: Dear recipient name: "blank line first line of the body second line of the body last line of the body "blank line" Sincerely, "blank line" sender name For example, assuming that you have the sender named John and the recipient named Mary. John wrote two lines of the letter: 1: "How are you?" 2: I really miss you! Your test file leveraging this Letter class will have the following output:

Explanation / Answer

Code

class Letter: ##letter class
lFrom = "" ##class variables
lTo = ""
body = "" ##varible to store the body of the letter
def __init__(self, letterFrom, letterTo): ##constructor
self.lTo = letterTo
self.lFrom = letterFrom
  
def addLines(self, line): ##add the line came in the argument to the body
self.body += line
self.body += " "
  
def getText(self): ##return the text with letter format
return "Dear "+self.lTo + " " + self.body + " Sincerely " + self.lFrom
  
letter = Letter("Merry","John")
letter.addLines("I am soorry we must part")
letter.addLines("I wish you all the best")
print (letter.getText())

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