Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Just dictionary and strings solution in Clear category for Morse Clock by Kolia951
def checkio(time):
morse2 = {
"0": "..",
"1": ".-",
"2": "-.",
}
morse3 = {
"0": "...",
"1": "..-",
"2": ".-.",
"3": ".--",
"4": "-..",
"5": "-.-",
"6": "--.",
}
morse4 = {
"0": "....",
"1": "...-",
"2": "..-.",
"3": "..--",
"4": ".-..",
"5": ".-.-",
"6": ".--.",
"7": ".---",
"8": "-...",
"9": "-..-",
}
result = [i.rjust(2, "0") for i in time.split(":")]
hours = morse2.get(result[0][0]) + " " + morse4.get(result[0][1])
minutes = morse3.get(result[1][0]) + " " + morse4.get(result[1][1])
seconds = morse3.get(result[2][0]) + " " + morse4.get(result[2][1])
return hours + " : " + minutes + " : " + seconds
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!")
Oct. 17, 2022
Comments: