Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import winsound
  5.  
  6. MorsToDict = {'.-' : 'a', '-...' : 'b', '-.-.' : 'c', '-..': 'd',
  7.            '.': 'e', '..-.': 'f', '--.' : 'g', '....' : 'h', '..' : 'i',
  8.            '.---': 'j', '-.-': 'k', '.-..': 'l', '--': 'm', '-.': 'n',
  9.            '---': 'o', '.--.': 'p', '--.-':'q', '...': 's', '-':'t', '..-':'u',
  10.            '...-' : 'v', '.--': 'w', '-..-': 'x', '-.--': 'y', '--..' : 'z'}
  11.  
  12. DictToMors = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.',
  13.               'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j':'.---',
  14.               'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.',
  15.               'o': '---', 'p': '.--.', 'q':'--.-', 's':'...', 't': '-',
  16.               'u': '..-', 'v': '...-', 'w': '.--', 'x':'-..-', 'y':'-.--',
  17.               'z': '--..'}
  18. def code(s):
  19.     str = ""
  20.     for i in s:
  21.         if i == ' ':
  22.             str+= '/'
  23.         else:
  24.             str+= DictToMors[i]
  25.             str+= '/'
  26.     return str
  27.  
  28. def decode(s):
  29.     str = ""
  30.     hp = ""
  31.     if s[:-1] != '/':
  32.         s+='/'
  33.     licz = 0
  34.     if s[0] != '/':
  35.         for i in s:
  36.             if i == '/':
  37.                 licz+= 1
  38.                 if hp != "":
  39.                     str += MorsToDict[hp]
  40.                 if licz == 2:
  41.                     str += ' '
  42.                 hp = ""
  43.             else:
  44.                 hp += i
  45.                 licz = 0
  46.         str.replace('', '')
  47.     return str
  48.  
  49. d = raw_input()
  50.  
  51. asd = decode(d)
  52. print(asd)
  53. winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement