Advertisement
Dimitar182

String Game

Apr 2nd, 2023
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. string = input()
  2. while True:
  3.     command = input().split(" ")
  4.     action = command[0]
  5.     if action == "Done":
  6.         break
  7.  
  8.     if action == "Change":
  9.         char = command[1]
  10.         replacement = command[2]
  11.         string = string.replace(char, replacement)
  12.         print(string)
  13.  
  14.     elif action == "Includes":
  15.         substring = command[1]
  16.         print(substring in string)
  17.  
  18.     elif action == "End":
  19.         substring = command[1]
  20.         print(string.endswith(substring))
  21.  
  22.     elif action == "Uppercase":
  23.         string = string.upper()
  24.         print(string)
  25.  
  26.     elif action == "FindIndex":
  27.         char = command[1]
  28.         print(string.index(char))
  29.  
  30.     elif action == "Cut":
  31.         start_index = int(command[1])
  32.         count = int(command[2])
  33.         cut_chars = string[start_index:start_index + count]
  34.         string = cut_chars
  35.         print(cut_chars)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement