码迷,mamicode.com
首页 > 编程语言 > 详细

python 练习洗牌

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

标签:class   div   utf-8   pos   字母   coding   大小   str   print   

扑克牌:

#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 练习洗牌

标签:class   div   utf-8   pos   字母   coding   大小   str   print   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!