python面向对象 换牌小测试

‘’’
两只手换牌
属性:两只手 牌
行为换牌
‘’’
class Card:

def __init__(self):
    self.num=""
    self.color=""

class Hand:
def init(self):
self.card=""
class Person:
def init(self):
self.left_hand=None
self.right_hand=None
def change(self):
c=self.left_hand
self.left_hand=self.right_hand
self.right_hand=c
c1=Card()
c1.color=“♣”
c1.num=“3”

c2=Card()
c2.color=“♥”
c2.num=“4”

l=Hand()
l.card=c2.color+c1.num

r=Hand()
r.card=c2.color+c2.num

p=Person()
p.left_hand=l
p.right_hand=r
p.change()
print(p.left_hand.card,p.right_hand.card)

猜你喜欢

转载自blog.csdn.net/qq_38636998/article/details/82863172