python中有关于exception的疑问,需要创造两种错误的类(LenError和TypeError)

python中有关于exception的疑问,需要创造两种错误的类(LenError和TypeError),怎么解决呢?

img

class LenError(Exception):
    pass
class TypeError(Exception):
    pass

def isValidID(IDnum):
    try:
        if len(str(IDnum))!=4:
            raise LenError()
        if type(1)!=type(IDnum):
            raise TypeError()
        return "Valid ID number"
    except LenError as e:
        return "The length of your ID is not valid"
    except TypeError as e:
        return "The type of your ID is not valid"
print(isValidID('1234'))
print(isValidID(12345))
print(isValidID(1234))
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632