Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Morse Clock by radek120299
CYFRY2= {'0': '....', '1': '...-', '2': '..-.',
'3': '..--', '4': '.-..', '5': '.-.-',
'6': '.--.', '7': '.---', '8': '-...',
'9': '-..-'
}
CYFRYH={'0': '..', '1': '.-', '2': '-.'}
CYFRYMiS={'0': '...', '1': '..-', '2': '.-.',
'3': '.--', '4': '-..', '5': '-.-',
'6': '--.'}
def checkio(time_string: str) -> str:
odp=""
hours=[]
minutes=[]
seconds=[]
time_string=time_string.split(':')
print(time_string)
hours.append(time_string[0])
minutes.append(time_string[1])
seconds.append(time_string[2])
if len(hours[0])==1:
hours[0]="0"+hours[0][:]
if len(minutes[0])==1:
minutes[0]="0"+minutes[0][:]
if len(seconds[0])==1:
seconds[0]="0"+seconds[0][:]
odp=odp+CYFRYH[hours[0][0]]+" "+CYFRY2[hours[0][1]]+" "+": "+CYFRYMiS[minutes[0][0]]+" "+CYFRY2[minutes[0][1]]+" "+": "+CYFRYMiS[seconds[0][0]]+" "+CYFRY2[seconds[0][1]]
return odp
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!")
Nov. 4, 2018