Advertisement
horozov86

Secret Chat

Mar 21st, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. message = input()
  2.  
  3. while True:
  4.     line = input()
  5.     if line == "Reveal":
  6.         break
  7.  
  8.     line_split = line.split(":|:")
  9.     command = line_split[0]
  10.  
  11.     if command == "InsertSpace":
  12.         given_index = int(line_split[1])
  13.         message = message[:given_index] + " " + message[given_index:]
  14.         print(message)
  15.  
  16.     elif command == "Reverse":
  17.         substring = line_split[1]
  18.         if substring in message:
  19.             x = message.replace(substring, "", 1)
  20.             message = x + substring[::-1]
  21.             print(message)
  22.         else:
  23.             print("error")
  24.     else:
  25.         substring = line_split[1]
  26.         replacement = line_split[2]
  27.         y = message.replace(substring, replacement)
  28.         message = y
  29.         print(message)
  30.  
  31. print(f"You have a new text message: {message}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement