Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
f-string solution in Clear category for Morse Clock by imloafer
def checkio(time_string: str) -> str:
#replace this for solution
fmt = lambda t, i, j: f'{int(t[0]):0{i}b} {int(t[1]):0{j}b}'.replace('0', '.').replace('1', '-')
h, m, s = map(lambda x: f'{int(x):02}', time_string.split(':'))
h, m, s = fmt(h, 2, 4), fmt(m, 3, 4), fmt(s, 3, 4)
return f'{h} : {m} : {s}'
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!")
Feb. 8, 2023
Comments: