I think that one should start from another end by dividing seconds with 60 (to get seconds which don't fit into minutes), then dividing floor with 60 (to get minutes which don't fit into hours) and then divide with 60 to get hours. There is built-in divmod() for this type of calculations:
EDIT: following is code which doesn't deliver expected results but kept for context. Refer to second code snippet
EDIT: following is code which doesn't deliver expected results but kept for context. Refer to second code snippet
>>> seconds = 50007 >>> timeunits = list() >>> for i in range(3): # for sec, min and hrs ... seconds, unit = divmod(seconds, 60) ... timeunits.insert(0, unit) ... >>> timeunits [13, 53, 27] >>> ':'.join(str(unit) for unit in timeunits) '13:53:27'Second snippet delivering expected results:
>>> seconds = 500007 >>> minutes, seconds = divmod(seconds, 60) >>> hours, minutes = divmod(minutes, 60) >>> print(f'{hours}:{minutes}:{seconds}') 138:53:27
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.