Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by dig
def convert_digit_to_morse(digit, length):
binary = bin(digit)[2:].zfill(length)
morse = ''
for char in binary:
morse += ('.','-')[int(char)]
return morse
def checkio(time_string):
hour, minute, second = time_string.split(':')
hour, minute, second = int(hour), int(minute), int(second)
morse_hour = convert_digit_to_morse(hour // 10, 2) + ' ' + convert_digit_to_morse(hour % 10, 4)
morse_minute = convert_digit_to_morse(minute // 10, 3) + ' ' + convert_digit_to_morse(minute % 10, 4)
morse_second = convert_digit_to_morse(second // 10, 3) + ' ' + convert_digit_to_morse(second % 10, 4)
return rf'{morse_hour} : {morse_minute} : {morse_second}'
#replace this for solution
return ".- .... : .-- .--- : -.. -..-"
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!")
April 27, 2023
Comments: