Advertisement
SimeonTs

SUPyF2 Objects/Classes-Lab - 03. Email

Oct 18th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. """
  2. Objects and Classes - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1733#2
  4.  
  5. SUPyF2 Objects/Classes-Lab - 03. Email
  6.  
  7. Problem:
  8. Create class Email. The __init__ method should receive sender, receiver and a content.
  9. It should also have a default set to False attribute called is_sent. The class should have two additional methods:
  10. • send() - sets the is_sent attribute to True
  11. • get_info() - returns the following string: "{sender} says to {receiver}: {content}. Sent: {is_sent}"
  12. You will receive some emails until you receive "Stop" (separated by single space).
  13. The first will be the sender, the second one – the receiver and the third one – the content
  14. On the final line you will be given the indices of the sent emails separated by comma and space.
  15. Call the send() method for the given emails. For each email call the get_info() method
  16. Note: submit all of your code including the class
  17.  
  18. Example:
  19. Input:
  20. Peter John Hi,John
  21. John Peter Hi,Peter!
  22. Katy Lilly Hello,Lilly
  23. Stop
  24. 0, 2
  25.  
  26. Output:
  27. Peter says to John: Hi,John. Sent: True
  28. John says to Peter: Hi,Peter!. Sent: False
  29. Katy says to Lilly: Hello,Lilly. Sent: True
  30. """
  31.  
  32.  
  33. class Email:
  34.     def __init__(self, sender, receiver, content):
  35.         self.sender = sender
  36.         self.receiver = receiver
  37.         self.content = content
  38.         self.is_sent = False
  39.  
  40.     def send(self):
  41.         self.is_sent = True
  42.  
  43.     def get_info(self):
  44.         return f"{self.sender} says to {self.receiver}: {self.content}. Sent: {self.is_sent}"
  45.  
  46.  
  47. all_emails = []
  48. while True:
  49.     command = input().split()
  50.     if command[0] == "Stop":
  51.         break
  52.     email = Email(sender=command[0], receiver=command[1], content=command[2])
  53.     all_emails += [email]
  54.  
  55. for email in list(map(int, input().split(", "))):
  56.     all_emails[email].send()
  57.  
  58. [print(email.get_info()) for email in all_emails]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement