Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by BrianMcleod
def checkio(time_string: str) -> str:
d = [int(x) for x in time_string.split(':')]
out = f"{d[0]//10:02b} {d[0]%10:04b} : {d[1]//10:03b} {d[1]%10:04b} : {d[2]//10:03b} {d[2]%10:04b}"
return out.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!")
Aug. 17, 2018
Comments: