Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Morse esroM solution in Clear category for Morse Clock by CrossFireZero
def checkio(time_string):
time = []
h, m, s = time_string.split(':')
for value in (h.zfill(2), m.zfill(2), s.zfill(2)):
for digit in value:
time.append(str(bin(int(digit)))[2:].zfill(4).replace('1', '-').replace('0', '.'))
return time[0][2:] + ' ' + time[1] + ' : ' + time[2][1:] + ' ' + time[3] + ' : ' + time[4][1:] + ' ' + time[5]
if __name__ == '__main__':
print("Example:")
print(checkio("10:37:49"))
#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"
print("Coding complete? Click 'Check' to earn cool rewards!")
Aug. 22, 2019