首页 > 编程语言 > 详细

python 练习洗牌

时间:2018-01-20 00:01:59      阅读:343      评论:0      收藏:0      [点我收藏+]

扑克牌:

#coding=utf-8
import random

poker_num = [str(i) for i in range(2,11)] #数字牌
poker_str = [‘A‘,‘J‘,‘Q‘,‘K‘]  #字母牌
poker_king = [‘大王‘,‘小王‘] #大小王
poker_color = [‘红‘,‘黑‘,‘方‘,‘花‘] #花色

pokers = [‘%s%s‘%(i,j) for i in poker_color for j in poker_num+poker_str] + poker_king #生成54张牌
print(len(pokers))

random.shuffle(pokers) #随机洗牌
#print(pokers)

poker_a = pokers[0:51:3] #斗地主玩法
poker_b = pokers[1:51:3]
poker_c = pokers[2:51:3]
last_3 = pokers[-3:]
print(‘A:‘,poker_a)
print(‘B:‘,poker_b)
print(‘C:‘,poker_c)
print(‘最后三张:‘,last_3)

  

大乐透:

#coding=utf-8
import random

daletou_qian = [i for i in range(1,36)]
daletou_hou = [i for i in range(1,13)]
daletou_qian_random = random.sample(daletou_qian,k=5)
daletou_hou_random = random.sample(daletou_hou,k=2)
print(daletou_qian_random+daletou_hou_random)

 

python 练习洗牌

原文:https://www.cnblogs.com/feiyueNotes/p/8319198.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!