定义Time类Python Pta

这段代码用样例算出来结果都能对上但是就是会显示答案错误是为什么呢?还有别的情况吗
代码如下:

class Time:
def init(self,h,m,s):
self.h = h
self.m = m
self.s = s

def showTime12(self):
    if self.h>24 or self.m>60 or self.s>60 or self.h<0 or self.m<0 or self.s<0:
        print('00:00:00')
    else:
        if self.h <= 12:
            print('{:0>2}:{:0>2}:{:0>2} AM'.format(self.h,self.m,self.s))
        else:
            print('{:0>2}:{:0>2}:{:0>2} PM'.format(self.h%12,self.m,self.s))

def showTime24(self):
    if self.h>24 or self.m>60 or self.s>60 or self.h<0 or self.m<0 or self.s<0:
        print('00:00:00')
    else:
        print('{:0>2}:{:0>2}:{:0>2}'.format(self.h,self.m,self.s))

img

img

如果用datetime库函数来转换就非常方便,并且不容易出错:

class Time:
    def __init__(self,h,m,s):
        self.h = h
        self.m = m
        self.s = s

    def showTime12(self):
        from datetime import datetime as dt
        try:
            strtime = ':'.join(map(str,(self.h,self.m,self.s)))
            print(dt.strptime(strtime,'%H:%M:%S').strftime('%I:%M:%S %p'))
        except:
            print('00:00:00')

    def showTime24(self):
        from datetime import datetime as dt
        try:
            strtime = ':'.join(map(str,(self.h,self.m,self.s)))
            print(dt.strptime(strtime,'%H:%M:%S').strftime('%H:%M:%S'))
        except:
            print('00:00:00')

hh, mm, ss = [int(x) for x in input().split()]
t = Time(hh, mm, ss)
t.showTime12()
t.showTime24()

有这样的情况

img