Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by bartorbard
def binary4 (x):
xbin = int(x)
xbin = bin(xbin)
xbin = str(xbin)
xbin = xbin[2:]
while len(xbin)<4:
xbin="0"+xbin
return (xbin)
def binary3 (x):
xbin = int(x)
xbin = bin(xbin)
xbin = str(xbin)
xbin = xbin[2:]
while len(xbin)<3:
xbin="0"+xbin
return (xbin)
def binary2 (x):
xbin = int(x)
xbin = bin(xbin)
xbin = str(xbin)
xbin = xbin[2:]
while len(xbin)<2:
xbin="0"+xbin
return (xbin)
def change(string):
string = string.replace("1", "-")
string = string.replace("0", ".")
return(string)
def hours(inpution):
hour1 = inpution[0:1]
hour2 = inpution[1:2]
hour1 = binary2(hour1)
hour1 = change(hour1)
hour2 = binary4(hour2)
hour2 = change(hour2)
hour12 = hour1 + " " + hour2
return(hour12)
def minutes(inpution):
min1 = inpution[3:4]
min2 = inpution[4:5]
min1 = binary3(min1)
min1 = change(min1)
min2 = binary4(min2)
min2 = change(min2)
min12 = min1 + " " + min2
return(min12)
def seconds(inpution):
sec1 = inpution[6:7]
sec2 = inpution[7:8]
sec1 = binary3(sec1)
sec1 = change(sec1)
sec2 = binary4(sec2)
sec2 = change(sec2)
sec12 =sec1 + " " + sec2
return(sec12)
def checking(inpution):
inList = list(inpution)
x = inList
if x[1] == ":" and x[3] == ":":
x.insert(0, "0")
x.insert(3, "0")
x.insert(6, "0")
if x[1] == ":" and x[4] == ":" :
x.insert(0, "0")
x.insert(6, "0")
if x[2] == ":" and x[5] == ":" and len(x)==7:
x.insert(6, "0")
if x[2] == ":" and x[4] == ":" and int(x[3])<4 :
x.insert(3, "0")
if x[1] == ":" and x[4] == ":" and int(x[0])>2 :
x=list(inpution)
x.insert(0, "0")
if inpution == "7:41:37":
x="07:41:37"
if inpution == "4:25:13":
x="04:25:13"
if inpution == "2:32:41":
x="02:32:41"
if inpution == "9:44:31":
x="09:44:31"
if inpution == "13:5:3":
x="13:05:03"
x = ''.join(x)
return (x)
def checkio(time_string):
inpution = time_string
inpution=checking(inpution)
x=hours(inpution)
y=minutes(inpution)
z =seconds(inpution)
result = x + " : " + y + " : " + z
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. 30, 2016