python天生4人扑克牌手牌

python天生4人扑克牌手牌

连载一段网友用python写的扑克牌发放营业牌照代码

两个本领天生,解释掉的实质为一次发够13张

'''2 随机天生扑克牌牌的4手牌(4部分的牌局,没手13张,没有巨细王)'''

import random

num = []

#代办红桃,方块,黑桃,梅花

for i in ['Hearts','Cube','Spades','plum']:

for j in ['2','3','4','5','6','7','8','9','10','J','Q','K','A']:

num.append(i+j)

#random.shuffle() 讲序列中的实质随机打乱

random.shuffle(num)

#天生二维game

game = [[] for i in range(4)]

#一次性发13张

'''

for i in range(4):

while len(num) > 0:

game[i].append(num[0])

num.pop(0)

if len(game[i])==13 :

break

for i in range(4):

print("第{}部分的手牌为:\n".format(i+1),game[i])

'''

#一次发一张

for i in range(52):

if len(num) == 0:

break

game[i%4].append(num[0])

#简略第一个元素

num.pop(0)

for i in range(4):

print("第{}部分的手牌为:\n".format(i+1),game[i])

分享到 :

Leave a Reply

Your email address will not be published. Required fields are marked *