一副扑克牌包含4种花色,12个数值,1个小王,1个大王,实现随机生成一张牌
代码如下:
#coding=utf-8
import random
def poker():
color = random.randint(0,4)
huase = ['黑桃','红桃','方块','梅花','王']
card = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']
if color in range(0,4):
value = random.randint(0,12)
elif color == 4:
value = random.randint(0,1)
if value==0:
return "小王"
if value==1:
return "大王"
else:
return "错误的牌"
return huase[color]+card[value]
if __name__ == '__main__':
print poker()