class Poster:
def __init__(self):
self.postList=[]
def post(self,s):
self.postList.append(s)
print("发帖人:",s.posts)
print("发帖内容:",s.content)
class Reader:
def __init__(self):
self.likeList=[]
def like(self,s):
if s in self.likeList:
print('这个用户已经点赞过了')
else:
self.likeList.append(s)
print("点赞:",s.content)
s.like += 1
class User(Poster,Reader):
def __init__(self):
Poster.__init__(self)
Reader.__init__(self)
class Post:
def __init__(self,id,posts,content):
self.id=id
self.posts=posts
self.content=content
self.like=0
u1 = User()
u2 = User()
p1 = Post(1,"aaa","12345")
u1.post(p1)
p2 = Post(2,"bbb","6789")
u2.post(p2)
p3 = Post(3,"ccc","7654")
u1.post(p3)
u2.like(p1)
u2.like(p1)
u2.like(p3)
u1.like(p3)
print("p1点赞数:",p1.like)
print("p3点赞数:",p3.like)