karen_constantine

Untitled

Aug 22nd, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. print('Здравствуйте, вас приветствует программа Код Морзе')
  2. name = input('Как вас зовут?\n')
  3. letters = 'А Б В Г Д Е Ё Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я'
  4. letters = letters. split()
  5. morse = '.- -... .-- --. -.. . ...- --.. .. .--- -.- .-.. -- -. --- .--. .-. ... - ..- ..-. .... -.-. ---. ---- --.- --.-- -.-- -..- ..-.. ..-- .-.-'
  6. morse = morse.split()
  7. while True:
  8. answer = input(f'{name}, если вы хотите зашифровать, то нажмитье букву З, а если расшифровать - букву Р').lower()
  9. while answer not in ['р', 'з']:
  10. answer = input(f'{name}, если вы хотите зашифровать, то нажмитье букву З, а если расшифровать - букву Р').lower()
  11. text = ''
  12. translated_message = []
  13. message = input(f'{name}, введи свое сообщение\n').upper()
  14. if answer == 'з':
  15. list_incode = dict(zip(letters, morse))
  16. for complex in message:
  17. if complex not in list_incode:
  18. translated_message.append(complex)
  19. else:
  20. translated_message.append(list_incode[complex])
  21. text = ''.join(translated_message)
  22. elif answer == 'р':
  23. list_decode = dict(zip(morse, letters))
  24. message = message.split()
  25. for complex in message:
  26. if complex not in list_decode:
  27. translated_message.append(complex)
  28. else:
  29. translated_message.append(list_decode[complex])
  30. text = ''.join(translated_message)
  31. print(text)
  32. answer1 = input(f'Хотите воспользоваться программой еще раз? Да или Нет\n').lower()
  33. if answer1 == "да":
  34. print('Сделайте свой выбор снова')
  35. else:
  36. print('До свидания!')
  37. break
Advertisement
Add Comment
Please, Sign In to add comment