我创建了一个可以正确返回hh:mm时间格式的代码,但是当我在另一个文件中使用该代码时,与预期的输出相比,输出是不正确的。
例如:
它应该返回以下内容: 我们在05:00醒来 我们在05:30起床 我们又睡了06:10 最后电车于23:00出发 今天结束于23:59 明天从00:00开始
但是我的回报: 我们在05:00醒来 我们在05:30起床 我们又睡了06:10 最后电车于23:00出发 今天结束于23:59 明天开始于24:00
第24小时应变为00:00,我不确定如何解决。
class MilClock:
def __init__(self,hours,minutes):
self.hours = int(hours)
self.minutes = int(minutes)
def __str__(self):
return f"{self.hours:02}:{self.minutes:02}"
def addOne(self):
self.minutes += 1
if self.minutes >= 60:
self.minutes = 0
self.hours += 1
'''下一个文件,其中包含''
上方的代码from milclock import *
def addMinutes(clock,n):
for x in range(n):
clock.addOne()
hallClock = MilClock(5,0)
print('We wake up at',hallClock)
addMinutes(hallClock,30)
print('We get up at',40)
print('We are sleepy again by',hallClock)
wristWatch = MilClock(23,0)
print('Last tram leaves at',wristWatch)
addMinutes(wristWatch,59)
print('Today ends at',wristWatch)
wristWatch.addOne()
print('Tomorrow starts at',wristWatch)