Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by sebastian009
def checkio(time_string):
x2 = ["..",".-","-."]
x3 = ["...","..-",".-.",".--","-..","-.-","--."]
x4 = ["....","...-","..-.","..--",".-..",".-.-",".--.",".---","-...","-..-"]
d1 = time_string.find(":")
d2 = time_string.find(":",3)
h = time_string[:d1]
m = time_string[d1+1:d2]
s = time_string[d2+1:]
morse = ""
if len(str(h))>1:
morse = morse + str(x2[int(h[0])])+ " " + str(x4[int(h[1])]) + " : "
else:
morse = morse + str(x2[0])+ " " + str(x4[int(h)]) + " : "
if len(str(m))>1:
morse = morse + str(x3[int(m[0])])+ " " + str(x4[int(m[1])]) + " : "
else:
morse = morse + str(x3[0])+ " " + str(x4[int(m)]) + " : "
if len(str(s))>1:
morse = morse + str(x3[int(s[0])])+ " " + str(x4[int(s[1])])
else:
morse = morse + str(x3[0])+ " " + str(x4[int(s)])
return morse
Nov. 9, 2016