请问我的输出格式该怎么改
标准答案里分钟是00,而我是0,请问该怎么解决 发代码 n=eval(input())d=0
a=n//60//60
if a>24:
d=d+1
hour=n//60//60-24*d
mint=(n-hour*60*60-d*24*60*60)//60
m=n-mint*60-hour*60*60-d*24*60*60
print("{}day{}:{}:{}".format(d,hour,mint,m))
elif a<=24:
hour=n//60//60-24*d
mint=n//60
m=n-mint*60-hour*60*60-day*24*60*60
print("{}:{}:{}".format(hour,mint,m)) 本帖最后由 jackz007 于 2021-12-2 13:20 编辑
没什么好办法,只能把这些数都变成长度为 2 的字符串
n=eval(input())
d=0
a=n//60//60
if a>24:
d=d+1
hour=n//60//60-24*d
mint=(n-hour*60*60-d*24*60*60)//60
m=n-mint*60-hour*60*60-d*24*60*60
hour = str(hour)
if len(hour) < 2 : hour = '0' + hour
mint = str(mint)
if len(mint) < 2 : mint = '0' + mint
m = str(m)
if len(m) < 2 : m = '0' + m
print("{} day {}:{}:{}" . format(d , hour , mint , m))
elif a<=24:
hour=n//60//60-24*d
mint=n//60
m=n-mint*60-hour*60*60-day*24*60*60
hour = str(hour)
if len(hour) < 2 : hour = '0' + hour
mint = str(mint)
if len(mint) < 2 : mint = '0' + mint
m = str(m)
if len(m) < 2 : m = '0' + m
print("{}:{}:{}".format(hour , mint , m)) 问题是最后的输出形式是21:00:12而我是21:0:12 本帖最后由 qq1151985918 于 2021-12-2 13:24 编辑
>>> f = lambda n: str(n).rjust(2, "0")
>>> f(0)
'00'
>>> f(9)
'09'
>>> f(16)
'16'
>>> print("{}day{}:{:0>2d}:{:0>2d}".format(d,hour,mint,m))
结果:
162012
1day21:00:12
页:
[1]