Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Ambulanss
def checkio(time_string):
firstindex = time_string.find(':', 0)
secondindex = time_string.find(':', firstindex + 1)
hours = time_string[:firstindex]
minutes = time_string[firstindex+1 : secondindex]
seconds = time_string[secondindex+1:]
print(hours)
print(minutes)
print(seconds)
result = ""
if len(hours) == 1:
hours = '0' + hours
if len(minutes) == 1:
minutes = '0' + minutes
if len(seconds) == 1:
seconds = '0' + seconds
result = '{0:02b}'.format(int(hours[0])) + ' ' + '{0:04b}'.format(int(hours[1])) + ' : ' + '{0:03b}'.format(int(minutes[0])) + ' ' '{0:04b}'.format(int(minutes[1])) + ' : ' + '{0:03b}'.format(int(seconds[0])) + ' ' '{0:04b}'.format(int(seconds[1]))
result = result.replace('0', '.')
result = result.replace('1', '-')
print (result)
return result
if __name__ == '__main__':
#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"
Nov. 13, 2016