class Person:
def __init__(self,name):
self.name = name
def open(self, obj_door):
print(f'{self.name}默念三声:芝麻开门......')
obj_door.open_door()
def close(self, obj_d):
print(f'{self.name}默念三声:芝麻关门......')
obj_d.close_door()
class Door:
def __init__(self, name):
self.name = name
def open_door(self):
print(f'{self.name}房间门被打开了......')
def close_door(self):
print(f'{self.name}房间门被关上了......')
p1 = Person('albert')
door8208 = Door(8208)
p1.open(door8208)
p1.close(door8208)
class Boy:
def __init__(self, name):
self.name = name
def meet(self, girl_friend=None):
self.girl_friend = girl_friend
def have_diner(self):
if self.girl_friend:
print(f'{self.name}请{self.girl_friend.age}岁的{self.girl_friend.name}一起去海底捞吃火锅!!!好浪漫啊')
self.girl_friend.shopping(self)
else:
print('单身狗,随便吃点吧!!!')
class Girl:
def __init__(self, name, age):
self.name = name
self.age = age
def shopping(self, boy):
print(f'{self.name}想让{boy.name}陪她去逛商场, 太浪漫了啊!')
boy_albert = Boy('albert')
girl_hugu = Girl('hugu', 17)
boy_albert.meet(girl_hugu)
boy_albert.have_diner()
|