I’m creating a function that receives the tenths of second (t) and returns a processed string (digital clock like).
Is there a better/easier/optimum way to do it?
Output format: A:BC.D (Minutes : Seconds . Tenths)
def format(t):
A = 0
B = 0
C = 0
D = t
if t >= 10:
C = t // 10
D = t % 10
if C >= 10:
B = C // 10
C = C % 10
if B >= 6:
A = B // 6
B = B % 6
return str(A) + ":" + str(B) + str(C) + "." + str(D)
All those
ifsare completely unnecessary, and a few other things can be simplified: