0
所以我寫了一個python代碼,將秒轉換成小時分鐘和秒,但代碼看起來不整齊。什麼是更好的方式來做我的腳本正在做什麼?有沒有更簡單的方法來做到這一點?
from fractions import Fraction as Frac
from decimal import Decimal as Deci
def Hrs(mins,hr=[],deci=[],hrs=True):
return(Seperator(mins/60))
def Seperator(Decimal,num=[],deci=[],nums=True):
del num[:],deci[:]
for item in str(Decimal):
if item == '.':
deci.append(item)
nums = False
continue
num.append(item)if nums else deci.append(item)
return''.join(num),''.join(deci)
def Mins(secs):
t = Deci(float(Frac(secs,60)))
return t
def Secs(deci):
r = Deci(float(deci*60))
return r
def Clean(decimal,deci=[],p=True):
del deci[:]
for item in str(decimal):
if item == '.':
if p:deci.append(item);p=False;continue
else: break
deci.append(item)
return float(''.join(deci))
if __name__ == '__main__':
Seconds = 6033
Hours = Hrs(Mins(Seconds))[0]
Minutes = int(Secs(Clean(Hrs(Mins(Seconds))[1])))
Seconds = int(eval(Seperator(Secs(Clean(Hrs(Mins(Seconds))[1])))[1])*60)
print '{}:{}:{}'.format(Hours,Minutes,Seconds)