马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
要求:艺术团招生,在3岁至10岁之间的孩子
class Children():
def __init__(self,name,age,district):
self.name=name
self.age=age
self.district=district
class Art_group():
def __init__(self):
self.child=0
def __str__(self):
return f"招生:姓名{self.name},年龄{self.age},地区{self.district}"
def add_children(self,item):
if 3<self.age<=10 :
self.child += 1
print(f"已经招生了{self.child}人!")
else :
print("不满足招生条件!")
a=Children("完么智曲",6,"青海")
gyl=Art_group()
gyl.add_children(a)
print(gyl)
class Child():
def __init__(self, name, age, district):
self.name = name
self.age = age
self.district = district
class Artist():
def __init__(self):
self.group = list()
def __str__(self):
detail = list()
for each in self.group:
detail.append(f"姓名:{each.name} 年龄:{each.age} 地区:{each.district}")
detail = '\n'.join(detail)
return detail
def add(self, child: Child):
if 3 >= child.age > 10:
print("不满足招生条件!")
else:
self.group.append(child)
print(f"已经招生了{len(self.group)}人!")
dragov = Child("完么智曲", 6, "青海")
artist = Artist()
artist.add(dragov)
print(artist)
|