Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. exp = input()
  2. cmd = input()
  3. while cmd != "Finish":
  4.     cmd = cmd.split(" ")
  5.     if cmd[0] == "Replace":
  6.         cur = cmd[1]
  7.         new = cmd[2]
  8.         exp = exp.replace(cur, new, exp.find(cur))
  9.         print(exp)
  10.     if cmd[0] == "Cut":
  11.         startIdx = int(cmd[1])
  12.         endIdx = int(cmd[2])
  13.         if 0 <= startIdx <= endIdx < len(exp):
  14.             removeString = exp[startIdx:endIdx + 1]
  15.             exp = exp.replace(removeString, "")
  16.             print(exp)
  17.         else:
  18.             print("Invalid indexes!")
  19.     if cmd[0] == "Make":
  20.         if cmd[1] == "Upper":
  21.             exp = exp.upper()
  22.         else:
  23.             exp = exp.lower()
  24.         print(exp)
  25.     if cmd[0] == "Check":
  26.         contains = cmd[1]
  27.         if contains in exp:
  28.             print(f"Message contains {contains}")
  29.         else:
  30.             print(f"Message doesn't contain {contains}")
  31.     if cmd[0] == "Sum":
  32.         startIdx = int(cmd[1])
  33.         endIdx = int(cmd[2])
  34.         if 0 <= startIdx <= endIdx < len(exp):
  35.             string = exp[startIdx:endIdx + 1]
  36.             sum = 0
  37.             for char in string:
  38.                 sum += ord(char)
  39.             print(sum)
  40.         else:
  41.             print("Invalid indexes!")
  42.     cmd = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement