python 练习题之 猫

class Cat:

    def __init__(self,name=None,age=None,color=None):
        self.__name=name
        self.__age=age
        self.__color=color

    def setName(self,name):
        self.__name=name
    def setAge(self,age):
        if age<0:
            print("年龄不合法")
            self.__age=0
        else:
            self.__age = age
    def setColor(self,color):
        self.__color=color

    # def setvalue(self,name,age,color):
    #     self.__name=name
    #     self.__age=age
    #     self.__color=color
    def getName(self):
        return self.__name
    def show(self):
        print("姓名:%s年龄:%d,颜色:%s"
              %(self.__name,self.__age,self.__color))


c1=Cat("小花",10,'白色')
# c1.setName("小花")
# c1.setAge(-10)
# c1.setColor("白色")
c1.show()

c2=Cat()
c2.setName("小白")
c2.setAge(2)
c2.setColor("花色")
c2.show()

while True:
    name = input("请输入姓名:")
    if name == c1.getName():
        print("有这只猫")
        c1.show()
        break
    elif name == c2.getName():
        print("有这只猫")
        c2.show()
        break
    else:
        print("没有")

 

posted @ 2018-12-21 21:54  青春叛逆者  阅读(309)  评论(0编辑  收藏  举报