Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
morse clock solution in Clear category for Morse Clock by Nirmala
def code(d):
if d == "0":
return "...."
elif d == "1":
return "...-"
elif d == "2":
return "..-."
elif d == "3":
return "..--"
elif d == "4":
return ".-.."
elif d == "5":
return ".-.-"
elif d == "6":
return ".--."
elif d == "7":
return ".---"
elif d == "8":
return "-..."
elif d == "9":
return "-..-"
def checkio(time_string):
x = " "
time = time_string.split(":")
for p in time:
h = time[0]
m = time[1]
s = time[2]
for t in h:
if len(h) < 2:
h = "0" + h
ha = str(code(h[0]))
ha = ha[2:]
hb = str(code(h[1]))
for i in m:
if len(m) < 2:
m = "0" + m
ma = str(code(m[0]))
ma = ma[1:]
mb = str(code(m[1]))
for e in s:
if len(s) < 2:
s = "0" + s
sa = str(code(s[0]))
sa = sa[1:]
sb = str(code(s[1]))
return ha + x + hb + " : " + ma + x + mb + " : " + sa + x + sb
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio("00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
Nov. 22, 2016