python - I got processed with exit code 0 -
i finished writing code assignment , here questions following problems relate email messaging system. work problems in same file.:
(a) design class message models e-mail message. message has recipient, sender, , message text. support following methods: - constructor takes sender , recipient - method append appends line of text message body - method tostring makes message 1 long string (notice each line in new line): "from: harry morgan to: rudolf reindeer . . ."
(b) design class mailbox stores e-mail messages, using message class of exercise 2a. implement following methods: - def addmessage(self, message) - def getmessage(self, index) - def removemessage(self, index)
(c) write program uses message , mailbox classes problems 2a , 2b make message, print , store in mailbox.
so before got jumpy, did code own , finished it, got nothing output processed exit code 0. don't understand why gives me outcome instead of output. if me great. thanks.
class message(): def __init__(self, mysender, myrecipient): self._sender = mysender self._recipient = myrecipient self._text = [] def getsender(self): return self._sender def getrecipient(self): return self._recipient def append(self, mymessage): self._text.append(mymessage) def tostring(self): out = "from: {}\nto: {}\n".format(self._sender, self._recipient) out += "\n".join(self._text) return out class mailbox(): def __init__(self): self._mails = [] def listmessage(self): output = [] i, message in enumerate(self._mails): output.append("[{}] from: {}, to: {}".format(i, message.get_sender(), message.get_recipient())) return "\n".join(output) def addmessage(self, message): self._mails.append(message) def getmessage(self, index): return self._mails[index].to_string() def removemessage(self, index): del self._mails[index]
here's corrected code main set up:
class message(): def __init__(self, mysender, myrecipient): self._sender = mysender self._recipient = myrecipient self._text = [] def getsender(self): return self._sender def getrecipient(self): return self._recipient def append(self, mymessage): self._text.append(mymessage) def tostring(self): out = "from: {}\nto: {}\ntext: {}".format(self._sender, self._recipient, self._text) return out class mailbox(): def __init__(self): self._mails = [] def listmessage(self): output = [] i, m in enumerate(self._mails): output.append(m.tostring()) #print(m.tostring()) return output def addmessage(self, message): self._mails.append(message) def getmessage(self, index): return self._mails[index].to_string() def removemessage(self, index): del self._mails[index] if __name__ == "__main__": mess = message("sender", "recipient") mess.append("hi there!") print(mess.tostring()) print("setting mailbox") mbox = mailbox() mbox.addmessage(mess) listemail = mbox.listmessage() print(listemail)
Comments
Post a Comment