Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Один из способов придумать пароль – взять фразу и оставить первые буквы
- # каждого слова. Написать функцию make_password, выполняющую задачу генерации
- # такого пароля из заданной фразы, при этом буквы i и I заменить на цифру 1,
- # буквы o и O на цифру 0, буквы s и S на цифру 5.
- #
- # Примеры:
- # make_password("The future belongs to those, Who believe in beauty of their dreams") ==> "TfbttWb1b0td"
- import traceback
- def make_password(phrase):
- password = ""
- for i in range(len(phrase.split(' '))):
- if phrase[0] == 'i' or 'I':
- phrase[0] = str(1)
- if phrase[0] == 'o' or 'O':
- phrase[0] = str(0)
- password.append(phrase[0])
- print(password)
- return password
- # Тесты
- try:
- assert make_password("Give me liberty or give me sweets") == "Gml0gm5"
- assert make_password("Keep Calm and Carry On") == "KCaC0"
- assert make_password("The future belongs to those, Who believe in beauty of their dreams") == "TfbttWb1b0td"
- except AssertionError:
- print("TEST ERROR")
- traceback.print_exc()
- else:
- print("TEST PASSED")
Advertisement
Add Comment
Please, Sign In to add comment