SHARE
TWEET

Untitled

a guest Jul 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class User:
  2.  
  3.     def __init__(self, Username, ReceivedMessages):
  4.         self.Username = Username
  5.         self.ReceivedMessages = ReceivedMessages
  6.  
  7.  
  8. class Message:
  9.  
  10.     def __init__(self, Content, Sender):
  11.         self.Content  = Content
  12.         self.Sender  =  Sender
  13.  
  14.  
  15. def Max_num(a,b):
  16.     if a > b:
  17.         return a
  18.     else:
  19.         return b
  20.  
  21.  
  22. if __name__ == '__main__':
  23.  
  24.         input_string = input().split(' ')
  25.         users_list = {}
  26.         message_list_1 = []
  27.         message_list_2 = []
  28.  
  29.         while not input_string[0] == 'exit':
  30.             if input_string[0] == 'register':
  31.                 newUser = User(input_string[1], [])
  32.                 users_list[input_string[1]] = newUser
  33.             else:
  34.                 for key, user in users_list.items():
  35.                     if user.Username == input_string[2]:
  36.                         newMessage = Message(input_string[3], input_string[0])
  37.                         user.ReceivedMessages.append(newMessage)
  38.  
  39.             input_string = input().split(' ')
  40.  
  41.         final_usernames = input().split(' ')
  42.  
  43.         for key,user in users_list.items():
  44.             if user.Username == final_usernames[1]:
  45.                 for messages in user.ReceivedMessages:
  46.                     if messages.Sender == final_usernames[0]:
  47.                         message_list_1.append(f'{messages.Sender}: {messages.Content}')
  48.  
  49.         for key,user in users_list.items():
  50.             if user.Username == final_usernames[0]:
  51.                 for messages in user.ReceivedMessages:
  52.                     if messages.Sender == final_usernames[1]:
  53.                         message_list_2.append(f'{messages.Content} :{messages.Sender}')
  54.  
  55.         if len(message_list_1) > 0 or len(message_list_2) > 0:
  56.             for i in range(0,Max_num(len(message_list_1),len(message_list_2))):
  57.                 if i < len(message_list_1):
  58.                     print(message_list_1[i])
  59.                 if i < len(message_list_2):
  60.                     print(message_list_2[i])
  61.         else:
  62.             print('No messages')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top