- #扑克类
- class Poker:
-
- def __init__(self,color,num):
- self.color = color
- self.num = num
-
- def __str__(self):
- return '{}{}'.format(self.color,self.num)
- #创建牌类对象
- p1 = Poker('?','K')
- p2 = Poker('?','A')
-
-
-
- #手类
- class Hond:
- def __init__(self,poker):
- self.poker = poker
-
- def hold_poker(self,poker):
- self.poker = poker
-
- #创建左右手对象
- life_hond = Hond(p1)
- right_hond = Hond(p2)
- # print(life_hond)
- # print(right_hond)
-
- #人类
- class Person:
-
- def __init__(self,name,life_fond,right_fond):
- self.name = name
- self.life_fond = life_fond
- self.right_fond = right_fond
-
- #展示手里的牌
- def show(self):
- print('{}张开双手'.format(self.name),end='')
- print('左手:{}'.format(self.life_fond.poker),end=',')
- print('右手:{}'.format(self.right_fond.poker))
-
- #交换手里的牌
- def swap(self):
- self.life_fond.poker,self.right_fond.poker = self.right_fond.poker,self.life_fond.poker
- print('{}交换俩手的牌'.format(self.name))
-
- #创建小明对象
- xiaoming = Person('小明',life_hond,right_hond)
-
- #展示手里的牌
- xiaoming.show()
-
- #交换手里的牌
-
- xiaoming.swap()
-
- #在展示手里的牌
-
- xiaoming.show()