Advertisement
Nenogzar

01. Password Reset

Mar 18th, 2024
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def take_odd(password):
  2.     return ''.join(password[i] for i in range(len(password)) if i % 2 != 0)
  3.  
  4. def cut_password(password, index, length):
  5.     return password[:index] + password[index+length:]
  6.  
  7. def substitute_password(password, substring, substitute):
  8.     if substring in password:
  9.         return password.replace(substring, substitute)
  10.     else:
  11.         return "Nothing to replace!"
  12.  
  13. def process(test_password):
  14.     password = test_password
  15.     command = input()
  16.     while command != "Done":
  17.         command_part = command.split(" ")
  18.         if command_part[0] == "TakeOdd":
  19.             password = take_odd(password)
  20.             print(password)
  21.         elif command_part[0] == "Cut":
  22.             index, length = command_part[1], command_part[2]
  23.             password = cut_password(password, int(index), int(length))
  24.             print(password)
  25.         elif command_part[0] == "Substitute":
  26.             substring, substitute_text = command_part[1], command_part[2]
  27.             password = substitute_password(password, substring, substitute_text)
  28.             print(password)
  29.  
  30.         command = input()
  31.  
  32.     print(f"Your password is: {password}")
  33.  
  34.  
  35. if __name__ == "__main__":
  36.     test_password = input()
  37.     process(test_password)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement