sibinasto

Problem 2 - 2.1.

Apr 3rd, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. def if_index_valid(index,string):
  2.     if 0 <= index < len(string):
  3.         return True
  4.     return False
  5.  
  6.  
  7. username = input()
  8. data = input()
  9. while not data == "Sign up":
  10.     command = data.split()
  11.     if command[0] == "Case":
  12.         if command[1] == 'lower':
  13.             username = username.lower()
  14.             print(username)
  15.         elif command[1] == 'upper':
  16.             username = username.upper()
  17.             print(username)
  18.     elif command[0] == "Reverse":
  19.         start_index, end_index = command[1:]
  20.         start_index = int(start_index)
  21.         end_index = int(end_index)
  22.         if if_index_valid(start_index,username) and if_index_valid(end_index,username):
  23.             new_Str = username[end_index:start_index-1:-1]
  24.             print(new_Str)
  25.  
  26.     elif command[0] == "Cut":
  27.         substring = command[1]
  28.         if substring in username:
  29.             username = username.replace(substring,'')
  30.             print(username)
  31.         else:
  32.             print(f"The word {username} doesn't contain {substring}.")
  33.     elif command[0] == "Replace":
  34.         old_char = command[1]
  35.         username = username.replace(old_char,"*")
  36.         print(username)
  37.     elif command[0] == "Check":
  38.         char = command[1]
  39.         if char in username:
  40.             print("Valid")
  41.         else:
  42.             print(f"Your username must contain {char}.")
  43.  
  44.  
  45.     data = input()
Advertisement
Add Comment
Please, Sign In to add comment