Advertisement
go6odn28

1_password_reset

Mar 24th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. def take_odd(text):
  2.     new_text = ''
  3.     for i, letter in enumerate(text):
  4.         if i % 2 != 0:
  5.             new_text += letter
  6.     print(new_text)
  7.     return new_text
  8.  
  9.  
  10. def cut_text(text, idx, length_):
  11.     substring = text[idx: idx + length_]
  12.     text = text.replace(substring, '', 1)
  13.     print(text)
  14.     return text
  15.  
  16.  
  17. def substitute_text(text, substring_, substitute_):
  18.     if substring_ in text:
  19.         text = text.replace(substring_, substitute_)
  20.         print(text)
  21.     else:
  22.         print("Nothing to replace!")
  23.     return text
  24.  
  25.  
  26. def main():
  27.     password = input()
  28.     while True:
  29.         command = input()
  30.         if command == "Done":
  31.             break
  32.         data = command.split()
  33.         command = data[0]
  34.         if command == "TakeOdd":
  35.             password = take_odd(password)
  36.  
  37.         elif command == "Cut":
  38.             index, length = int(data[1]), int(data[2])
  39.             password = cut_text(password, index, length)
  40.  
  41.         elif command == "Substitute":
  42.             substring, substitute = data[1], data[2]
  43.             password = substitute_text(password, substring, substitute)
  44.  
  45.     print(f"Your password is: {password}")
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     main()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement