Last active
January 23, 2020 07:12
-
-
Save Bundi-py/9c10182dba11d3298b645f67ff1c031b to your computer and use it in GitHub Desktop.
15. Dešifrovanje poruka pisanih Morzeovom azbukom, u oba smera, u zavisnosti od toga šta je uneto.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
morse = {'A': '.-', 'B': '-...', 'C': '-.-.', 'Č': '-..-', 'Ć': '--.-', 'D': '-..', 'DŽ': '-.--', 'Đ': '..-..', 'E': '.', 'F': '..-.', 'G': '--.', 'H': '....', 'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..', 'M': '--', 'N': '-.', 'O': '---', 'P': '.--.', 'Q': '--.-', 'R': '.-.', 'S': '...', 'Š': '----', 'T': '-', 'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-', 'Y': '-.--', 'Z': '--..', 'Ž': '.--', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', '6': '-....', '7': '--...', '8': '---..', '9': '----.', '0': '-----', '.': '.-.-.-', ',': '--..--', ':': '---...', ';': '-.-.-.', '?': '..--..', '!': '-.-.--', '-': '-....-', '/': '-..-.', '()': '..-.'} | |
poruka1 = [] | |
poruka2 = [] | |
biraj = input('Kako unosis poruku? (M za morzea, A za alfabet) ').upper() | |
if biraj == 'M': | |
por = input('Unesi poruku (ENTER to quit): ').upper() | |
poruka1 = por.split() | |
elif biraj == 'A': | |
poruka2 = input('Unesi poruku (ENTER to quit): ').upper() | |
for i in poruka1: | |
for key, value in morse.items(): | |
if i == value: | |
print(key, '', end='') | |
for i in poruka2: | |
for key, value in morse.items(): | |
if i == key: | |
print(value, ' ', end='') | |
*************************************************** | |
# ispis na ekranu 1 | |
Kako unosis poruku? (M za morzea, A za alfabet) a | |
Unesi poruku (ENTER to quit): proba je | |
.--. .-. --- -... .- .--- . | |
# ispis na ekranu 2 | |
Kako unosis poruku? (M za morzea, A za alfabet) m | |
Unesi poruku (ENTER to quit): .--. .-. --- -... .- .--- . | |
P R O B A J E | |
*************************************************** | |
Pantino rešenje: | |
print(' '.join({v:k for k, v in morse.items()}.get(l) for l in ".... . .-.. .-.. --- .-- --- .-. .-.. -..".split(' '))) | |
H E L L O W O R L D | |
print(' '.join(morse.get(l, ' ') for l in "HELLO WORLD")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment