Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by 9maksim
def checkio(time_string: str) -> str:
s = "".join([i.rjust(2,"0") for i in time_string.split(":")])
d = [int(i) for i in s]
b = f"{d[0]:02b} {d[1]:04b} : {d[2]:03b} {d[3]:04b} : {d[4]:03b} {d[5]:04b}"
m = b.replace("0",".").replace("1","-")
return m
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("00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
print("Coding complete? Click 'Check' to earn cool rewards!")
Dec. 14, 2019