Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Decoder by Joachim99
MORSE = {'.-': 'a', '-...': 'b', '-.-.': 'c',
'-..': 'd', '.': 'e', '..-.': 'f',
'--.': 'g', '....': 'h', '..': 'i',
'.---': 'j', '-.-': 'k', '.-..': 'l',
'--': 'm', '-.': 'n', '---': 'o',
'.--.': 'p', '--.-': 'q', '.-.': 'r',
'...': 's', '-': 't', '..-': 'u',
'...-': 'v', '.--': 'w', '-..-': 'x',
'-.--': 'y', '--..': 'z', '-----': '0',
'.----': '1', '..---': '2', '...--': '3',
'....-': '4', '.....': '5', '-....': '6',
'--...': '7', '---..': '8', '----.': '9','':''
}
def morse_decoder(code):
#replace this for solution
s=''
znaki=code.split(' ')
print(znaki)
for x in range(len(znaki)-1):
print(znaki[x])
if(znaki[x]=='' and znaki[x+1]==''):
s=s+' '
x=x+1
else:
s=s+MORSE[znaki[x]]
print(s)
s=s+MORSE[znaki[len(znaki)-1]]
if(ord(s[0])>96 and ord(s[0])<123):
s=chr(ord(s[0])-32)+s[1:]
print(s)
return s
def spacje(code):
lista=[]
for x in range(len(code)-2):
if(code[x]==' ' and code[x+1]==' ' and code[x+2]==' '):
lista.append(x)
return lista
if __name__ == '__main__':
print("Example:")
print(morse_decoder('... --- ...'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert morse_decoder("... --- -- . - . -..- -") == "Some text"
assert morse_decoder("..--- ----- .---- ---..") == "2018"
assert morse_decoder(".. - .-- .- ... .- --. --- --- -.. -.. .- -.--") == "It was a good day"
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 28, 2018