Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def if_index_valid(index,string):
- if 0 <= index < len(string):
- return True
- return False
- username = input()
- data = input()
- while not data == "Sign up":
- command = data.split()
- if command[0] == "Case":
- if command[1] == 'lower':
- username = username.lower()
- print(username)
- elif command[1] == 'upper':
- username = username.upper()
- print(username)
- elif command[0] == "Reverse":
- start_index, end_index = command[1:]
- start_index = int(start_index)
- end_index = int(end_index)
- if if_index_valid(start_index,username) and if_index_valid(end_index,username):
- new_Str = username[end_index:start_index-1:-1]
- print(new_Str)
- elif command[0] == "Cut":
- substring = command[1]
- if substring in username:
- username = username.replace(substring,'')
- print(username)
- else:
- print(f"The word {username} doesn't contain {substring}.")
- elif command[0] == "Replace":
- old_char = command[1]
- username = username.replace(old_char,"*")
- print(username)
- elif command[0] == "Check":
- char = command[1]
- if char in username:
- print("Valid")
- else:
- print(f"Your username must contain {char}.")
- data = input()
Advertisement
Add Comment
Please, Sign In to add comment