''' 扑克牌 ''' class Poker(): def __init__(self,color,number): self.color = color self.number = number #实例化对象 all_number = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] all_color = ['黑桃','红桃','梅花','方片'] all_poker = [] for j in all_color : for i in all_number : k = j+i k = Poker(j,i) all_poker.append(k.color+k.number) #print(all_poker) class Person(): def __init__(self,name): self.name = name a = Person('赵先生') b = Person('钱先生') c = Person('孙先生') d = Person('李先生') all_people = (a.name,b.name,c.name,d.name) #print(all_people) import random class Deal(): '''洗牌与发牌''' def xipai(all_poker): '''洗牌''' random.shuffle(all_poker) return all_poker def fapai(all_people,all_poker): '''发牌''' for k in range(len(all_poker)) : if k <= 12 : print('{}--->{}'.format(all_poker[k],all_people[0])) elif 13 <= k <= 25 : print('{}--->{}'.format(all_poker[k],all_people[1])) elif 26 <= k <= 38 : print('{}--->{}'.format(all_poker[k],all_people[2])) else : print('{}--->{}'.format(all_poker[k],all_people[3])) Deal.xipai(all_poker) #洗牌 #print(all_poker) print(''' ''') Deal.fapai(all_people,all_poker) #发牌
''' 扑克牌 ''' class Poker(): def __init__(self,color,number): self.color = color self.number = number #实例化对象 all_number = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'] all_color = ['黑桃','红桃','梅花','方片'] all_poker = [] for j in all_color : for i in all_number : k = j+i k = Poker(j,i) all_poker.append(k.color+k.number) #print(all_poker) import random q = [] w = [] e = [] r = [] random.shuffle(all_poker) for i in range(len(all_poker)) : if i <= 12 : q.append(all_poker[i]) elif 13 <= i <= 25 : w.append(all_poker[i]) elif 26 <= i <= 38 : e.append(all_poker[i]) else : r.append(all_poker[i]) print() print('赵先生的手牌是 {}'.format(q)) print() print('钱先生的手牌是 {}'.format(w)) print() print('孙先生的手牌是 {}'.format(e)) print() print('李先生的手牌是 {}'.format(r)) print()