Advertisement
viligen

morse_code_translator

Nov 11th, 2021
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. morse = {'.-': 'A',   '-...': 'B',   '-.-.': 'C','-..': 'D', '.': 'E', '..-.': 'F', '--.': 'G', '....': 'H', '..': 'I',
  2.          '.---': 'J',    '-.-': 'K',   '.-..': 'L', '--': 'M', '-.': 'N', '---': 'O', '.--.': 'P', '--.-': 'Q',
  3.          '.-.': 'R', '...': 'S', '-': 'T', '..-': 'U', '...-': 'V', '.--': 'W', '-..-': 'X', '-.--': 'Y', '--..': 'Z',
  4.          '-----': '0', '.----': '1', '..---': '2', '...--': '3', '....-': '4',  '.....': '5',  '-....': '6',
  5.          '--...': '7',  '---..': '8',  '----.': '9'}
  6.  
  7. morse_text = input().split("|")
  8.  
  9. new_text = ""
  10. for word in morse_text:
  11.     word_list = word.split()
  12.     new_word = ""
  13.     for ch in word_list:
  14.         letter = morse[ch]
  15.         new_word += letter
  16.     new_text += new_word + " "
  17.  
  18. print(new_text)
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement