Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- import winsound
- MorsToDict = {'.-' : 'a', '-...' : 'b', '-.-.' : 'c', '-..': 'd',
- '.': 'e', '..-.': 'f', '--.' : 'g', '....' : 'h', '..' : 'i',
- '.---': 'j', '-.-': 'k', '.-..': 'l', '--': 'm', '-.': 'n',
- '---': 'o', '.--.': 'p', '--.-':'q', '...': 's', '-':'t', '..-':'u',
- '...-' : 'v', '.--': 'w', '-..-': 'x', '-.--': 'y', '--..' : 'z'}
- DictToMors = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.',
- 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j':'.---',
- 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.',
- 'o': '---', 'p': '.--.', 'q':'--.-', 's':'...', 't': '-',
- 'u': '..-', 'v': '...-', 'w': '.--', 'x':'-..-', 'y':'-.--',
- 'z': '--..'}
- def code(s):
- str = ""
- for i in s:
- if i == ' ':
- str+= '/'
- else:
- str+= DictToMors[i]
- str+= '/'
- return str
- def decode(s):
- str = ""
- hp = ""
- if s[:-1] != '/':
- s+='/'
- licz = 0
- if s[0] != '/':
- for i in s:
- if i == '/':
- licz+= 1
- if hp != "":
- str += MorsToDict[hp]
- if licz == 2:
- str += ' '
- hp = ""
- else:
- hp += i
- licz = 0
- str.replace('', '')
- return str
- d = raw_input()
- asd = decode(d)
- print(asd)
- winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement