Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by lisovsky
def checkio(time_string: str) -> str:
return "{:0>2b} {:0>4b} : {:0>3b} {:0>4b} : {:0>3b} {:0>4b}".format(
*list(
map(
int,
list(
"".join(
["0" + s if len(s) == 1 else s for s in time_string.split(":")]
)
),
)
)
).translate(str.maketrans("01", ".-"))
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!")
Dec. 1, 2022