Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by tigerhu3180
def checkio(time_string: str) -> str:
results = [bin(int(j))[2:] for i in time_string.split(':') for j in i.zfill(2)]
results = [results[i].zfill(j).replace('0','.').replace('1','-') for i,j in enumerate([2,4,3,4,3,4])]
return ' : '.join(['{} {}'.format(results[i],results[i+1]) for i in [0,2,4]])
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!")
Sept. 30, 2018
Comments: