Vlad5080

devbug

Mar 30th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # Один из способов придумать пароль – взять фразу и оставить первые буквы
  2. # каждого слова. Написать функцию make_password, выполняющую задачу генерации
  3. # такого пароля из заданной фразы, при этом буквы i и I заменить на цифру 1,
  4. # буквы o и O на цифру 0, буквы s и S на цифру 5.
  5. #
  6. # Примеры:
  7. # make_password("The future belongs to those, Who believe in beauty of their dreams") ==> "TfbttWb1b0td"
  8.  
  9. import traceback
  10.  
  11.  
  12. def make_password(phrase):
  13.     password = ""
  14.  
  15.     for i in range(len(phrase.split(' '))):
  16.         if phrase[0] == 'i' or 'I':
  17.             phrase[0] = str(1)
  18.         if phrase[0] == 'o' or 'O':
  19.             phrase[0] = str(0)
  20.         password.append(phrase[0])
  21.     print(password)
  22.     return password
  23.  
  24.  
  25. # Тесты
  26. try:
  27.     assert make_password("Give me liberty or give me sweets") == "Gml0gm5"
  28.     assert make_password("Keep Calm and Carry On") == "KCaC0"
  29.     assert make_password("The future belongs to those, Who believe in beauty of their dreams") == "TfbttWb1b0td"
  30. except AssertionError:
  31.     print("TEST ERROR")
  32.     traceback.print_exc()
  33. else:
  34.     print("TEST PASSED")
Advertisement
Add Comment
Please, Sign In to add comment