Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
newbie solution in Clear category for Morse Clock by ewa_c
def morse(helpstring,digit):
result=""
for i in range(digit):
while len(helpstring)!=digit:
helpstring="0"+helpstring
if helpstring[i]=="1":
result+="-"
else:
result+="."
return result
def checkio(time_string):
i=0
j=0
list=["","",""]
newlist=['','','','','','']
final=""
for i in range(len(time_string)):
if time_string[i] == ":":
j+=1
else:
list[j]+=time_string[i]
i+=1
#print(list)
k=0
for i in range(3):
if len(list[i])==1:
list[i] = "0" + list[i]
for x in range(2):
newlist[k]=int(list[i][x])
k+=1
#print(list)
#print(newlist)
for i in range(6):
newlist[i]=bin(newlist[i])
newlist[i]=newlist[i][2:]
#print(newlist)
final = morse(newlist[0],2)
final += " " + morse(newlist[1],4)
final += " : " + morse(newlist[2],3)
final += " " + morse(newlist[3],4)
final += " : " + morse(newlist[4],3)
final += " " + morse(newlist[5],4)
print(final)
#replace this for solution
return final
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. 20, 2016