Advertisement
simeonshopov

String Manipulator

Mar 6th, 2020
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. text = input()
  2.  
  3. while True:
  4.     command = input()
  5.     if command == 'End':
  6.         break
  7.     args = command.split()
  8.     cmd = args[0]
  9.     if cmd == 'Translate':
  10.         old = args[1]
  11.         new = args[2]
  12.         text = text.replace(old, new)
  13.         print(text)
  14.     elif cmd == 'Includes':
  15.         sub_text = args[1]
  16.         if sub_text in text:
  17.             print('True')
  18.         else:
  19.             print('False')
  20.     elif cmd == 'Start':
  21.         sub_text = args[1]
  22.         if sub_text == text[:len(sub_text)]:
  23.             print('True')
  24.         else:
  25.             print('False')
  26.     elif cmd == 'Lowercase':
  27.         text = text.lower()
  28.         print(text)
  29.     elif cmd == 'FindIndex':
  30.         letter = args[1]
  31.         print(text.rindex(letter))
  32.     elif cmd == 'Remove':
  33.         start = int(args[1])
  34.         end = int(args[2]) + start
  35.         sub_text = text[start: end]
  36.         text = text.replace(sub_text, '')
  37.         print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement