Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- username = input()
- commands = list()
- def replace_letters_function(name, letters_function):
- if letters_function.lower() == "lower":
- name = name.lower()
- elif letters_function.lower() == "upper":
- name = name.upper()
- return name
- def reverse_function(name, start_idx, end_idx):
- if start_idx < end_idx:
- name_portion = name[start_idx:end_idx + 1]
- print(name_portion[::-1])
- def substring_function(name, substring):
- if substring in name:
- name = re.sub(substring, '', name)
- print(name)
- else:
- print(f"The username {name} doesn't contain {substring}.")
- def replace_char(name, character):
- new_name = []
- for char_idx in range(len(name)):
- if name[char_idx] != character:
- new_name.append(name[char_idx])
- else:
- new_name.append('-')
- return ''.join(new_name)
- def is_name_valid(name, character):
- if character in name:
- result = "Valid username."
- else:
- result = f"{character} must be contained in your username."
- return result
- def process_commands(name):
- for current_command in commands:
- if current_command[0] == "Letters":
- command_attribute = current_command[1]
- name = replace_letters_function(name, command_attribute)
- print(name)
- elif current_command[0] == "Reverse":
- command_attribute_1 = int(current_command[1])
- command_attribute_2 = int(current_command[2])
- if min(command_attribute_1, command_attribute_2) >= 0 \
- and max(command_attribute_1, command_attribute_2) < len(name):
- reverse_function(name, command_attribute_1, command_attribute_2)
- elif current_command[0] == "Substring":
- command_attribute = current_command[1]
- substring_function(name, command_attribute)
- elif current_command[0] == "Replace":
- command_attribute = current_command[1]
- name = replace_char(name, command_attribute)
- print(name)
- elif current_command[0] == "IsValid":
- command_attribute = current_command[1]
- print(is_name_valid(name, command_attribute))
- while True:
- command = input()
- if command == "Registration":
- break
- commands.append(command.split())
- process_commands(username)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement