Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by igor.v.dudenko
def checkio(time_string: str) -> str:
time_line = ''.join(x.rjust(2, '0') for x in time_string.split(':'))
d = list(int(x) for x in time_line)
res = f'{d[0]:02b} {d[1]:04b} : {d[2]:03b} {d[3]:04b} : {d[4]:03b} {d[5]:04b}'
return res.replace('0', '.').replace('1', '-')
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!")
Feb. 17, 2019