第一次
创建一只猫
‘’’
class cat():
def __init__(self,name,age):
self.name=name
self.age=age
def zhua(self):
print("猫抓老鼠")
创建一只老鼠
class mouse():
def __init__(self,name,zhonglei):
self.name=name
self.zhonglei=zhonglei
def fa(self):
print("一只猫抓一只老鼠")
创建猫抓老鼠
class teat():
def show(self,cat,mouse):
print("一个%d岁的名叫%s的猫抓到了一只名叫%s的小老鼠"%(cat.age,cat.name,mouse.name))
t=teat()
t_cat=cat("tom",5)
t_mouse=mouse("jerry","仓鼠")
t.show(t_cat,t_mouse)
‘’’
第二次
创建QQ企鹅
class qi():
def __init__(self,name,sex,health,Intimacy):
self.name=name
self.sex=sex
self.health=health
self.Intimacy=Intimacy
def is_sex(self,i):
if i ==1:
self.sex="Q仔"
else:
self.sex="Q妹"
def is_health(self,int_health):
if int_health > 1 and int_health < 100:
self.health=int_health
else:
self.health=60
def show(self):
print("宠物的自白")
print("我的名字是%s,健康值是%d,和主人的亲密度是%d,我的性别是%s"%(self.name,self.health,self.Intimacy,self.sex))
创建宠物狗
class dog():
def __init__(self,name,sex,health,Intimacy):
self.name=name
self.sex=sex
self.health=health
self.Intimacy=Intimacy
def is_sex(self,i):
if i ==1:
self.sex="Q仔"
else:
self.sex="Q妹"
def is_health(self,int_health):
if int_health > 1 and int_health < 100:
self.health=int_health
else:
self.health=60
def show(self):
print("宠物的自白")
print("我的名字是%s,健康值是%d,和主人的亲密度是%d,我的性别是%s"%(self.name,self.health,self.Intimacy,self.sex))
选择要领养的宠物
print("欢迎来到宠物店")
na=input("请输入您要领养的宠物名字:")
type=input("您要领养的宠物类型(1.狗2.企鹅):")
if type=="1":
gou=dog(na,"null",0,0)
int_sex =input("请输入1狗的性别(1.Q仔2.Q妹):")
gou.is_sex(int_sex)
int_health=int(input("请输入狗的健康值(1-100)"))
gou.is_health(int_health)
gou.show()
elif type =="2":
qier=qi(na,"null",0,0)
int_sex =input("请输入1企鹅的性别(1.Q仔2.Q妹):")
qier.is_sex(int_sex)
int_health=int(input("请输入企鹅的健康值(1-100)"))
qier.is_health(int_health)
qier.show()
else:
print("您输入的宠物类型这里没有")
|