Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by ail531
def checkio(time_string):
result_list = []
for item in time_string.split(':'):
if len(item) < 2:
item = '0' + item
for cipher in item:
result_list.append('{:08b}'.format(int(cipher)))
result = result_list[0][-2:] + ' ' + result_list[1][-4:] + ' : ' + result_list[2][-3:] + ' ' + result_list[3][-4:] + ' : ' + result_list[4][-3:] + ' ' + result_list[5][-4:]
return result.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!")
Sept. 26, 2019
Comments: