Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Andreas_Strus
def checkio(time_string):
dict = {'0': "....", "1": "...-", "2": "..-.", "3": "..--", "4": ".-..", "5": ".-.-", "6": ".--.", "7": ".---", "8": "-...", "9": "-..-"}
time_string = time_string.split(":")
time_mors = ""
h = ""
m = ""
s = ""
time = [h, m, s]
for x in [0, 1, 2]:
if len(time_string[x]) == 2:
time[x] = dict[str(time_string[x][0])] + " " + dict[str(time_string[x][1])]
if len(time_string[x]) == 1:
time[x] = dict["0"] + " " + dict[str(time_string[x][0])]
if time[0][0] == ".":
time[0] = time[0].replace(".", "", 1)
if time[0][0] == ".":
time[0] = time[0].replace(".", "", 1)
if time[1][0] == ".":
time[1] = time[1].replace(".", "", 1)
if time[2][0] == ".":
time[2] = time[2].replace(".", "", 1)
time_mors = time[0] + " : " + time[1] + " : " + time[2]
#replace this for solution
return time_mors
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"
Oct. 24, 2016