Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for Morse Clock by Doseg
def checkio(time_string: str) -> str:
#replace this for solution
hour, minute, second = time_string.split(":")
if len(hour) < 2: hour = '0' + hour
if len(minute) < 2: minute = '0' + minute
if len(second) < 2: second = '0' + second
time_binary = "{:02b} {:04b} : {:03b} {:04b} : {:03b} {:04b}".format(
int(hour[0]), int(hour[1]),
int(minute[0]), int(minute[1]),
int(second[0]), int(second[1]))
return time_binary.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!")
Jan. 29, 2019
Comments: