fork download
  1. class UserProfile:
  2. def __init__(self, name, age, location, password):
  3. self.name = name
  4. self.age = age
  5. self.location = location
  6. self.password = password
  7. self.friends = []
  8.  
  9. class ChatRoom:
  10. def __init__(self, name):
  11. self.name = name
  12. self.users = []
  13.  
  14. def add_user(self, user):
  15. self.users.append(user)
  16.  
  17. def encrypt_message(message):
  18. encrypted = ""
  19. for char in message:
  20. if char.isalpha():
  21. ascii_offset = 65 if char.isupper() else 97
  22. encrypted += chr((ord(char) - ascii_offset + 13) % 26 + ascii_offset)
  23. else:
  24. encrypted += char
  25. return encrypted
  26.  
  27. def exit_chat():
  28. print("Exiting chat...")
  29. return False
  30.  
  31. def handle_empty_messages(message):
  32. if message == "":
  33. print("Please enter a message.")
  34. return True
  35. return False
  36.  
  37. def send_emotions(message):
  38. emotions = [":)", ":D", ";-)"]
  39. for emotion in emotions:
  40. if emotion in message:
  41. print("Emotion detected!")
  42. return message
  43.  
  44. def add_friend(profile, friend_name):
  45. profile.friends.append(friend_name)
  46. print(friend_name + " added to friends list.")
  47.  
  48. def view_friends(profile):
  49. print("Friends:")
  50. for friend in profile.friends:
  51. print(friend)
  52.  
  53. user_profiles = [
  54. UserProfile("John", 25, "NY", "john123"),
  55. UserProfile("Alice", 30, "CA", "alice123"),
  56. UserProfile("Bob", 35, "FL", "bob123"),
  57. UserProfile("Mike", 20, "TX", "mike123"),
  58. UserProfile("Emma", 28, "IL", "emma123")
  59. ]
  60.  
  61. chat_rooms = [
  62. ChatRoom("Room1"),
  63. ChatRoom("Room2"),
  64. ChatRoom("Room3")
  65. ]
  66.  
  67. # Test the features
  68. current_user = user_profiles[0]
  69. add_friend(current_user, "David")
  70. view_friends(current_user)
  71.  
  72. message = "Hello :)!"
  73. if not handle_empty_messages(message):
  74. encrypted_message = encrypt_message(message)
  75. print("Encrypted message: " + encrypted_message)
  76. send_emotions(message)
  77.  
  78. print("Chat rooms:")
  79. for i, room in enumerate(chat_rooms):
  80. print(str(i+1) + ". " + room.name)
  81.  
  82. exit_chat()
Success #stdin #stdout 0.04s 63336KB
stdin
Standard input is empty
stdout
David added to friends list.
Friends:
David
Encrypted message: Uryyb :)!
Emotion detected!
Chat rooms:
1. Room1
2. Room2
3. Room3
Exiting chat...