Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
only format() solution in Clear category for Morse Clock by nickgryg
def checkio(time_string: str) -> str:
t = time_string.split(':')
t = "{:02d}{:02d}{:02d}".format(int(t[0]), int(t[1]), int(t[2]))
binary_clock = "{:02b} {:04b} : {:03b} {:04b} : {:03b} {:04b}".format(int(t[0]),
int(t[1]),
int(t[2]),
int(t[3]),
int(t[4]),
int(t[5]))
return binary_clock.replace('1', '-').replace('0', '.')
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. 12, 2019
Comments: