Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Morse Clock by alexandrov.net
def checkio(time_string: str) -> str:
time=time_string.split(':')
l=[] #list for 6 int '1:12:42'-> (0,1,1,2,4,2)
for x in range(len(time)):
if len(time[x])==1:
l.append(0)
l.append(int(time[x]))
else:
l+=[int(a) for a in time[x]]
#s=2 4 : 3 4 : 3 4 binary symbols
s=f'{l[0]:02b} {l[1]:04b} : {l[2]:03b} {l[3]:04b} : {l[4]:03b} {l[5]:04b}'
return s.replace('1','-').replace('0','.')
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!")
Oct. 5, 2018