開一個(gè)網(wǎng)站需要什么seo排名賺下載
利用方法:
1. random.randint( ) 隨機(jī)抽取數(shù)字 方法
2.random.sample((抽取范圍的參數(shù)),(抽取的個(gè)數(shù))) 返回的是列表 所以用[0]可以輸出里面的元素
import random# 1. 創(chuàng)建牌
# 花色
color = ["\u2660", "\u2663", "\u2665", "\u2666"]
# 數(shù)字
number = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
# 大小鬼
JOKER = ["KING", "QUEEN"]
# 空列表存放牌
cards = []
for i in color:for j in number:# 字符串拼接cards.append(i + j)
# 加入大小鬼
cards.extend(JOKER)# 2. 洗牌的方法(參數(shù):牌/次數(shù)(默認(rèn)=1))
def fy_shuffle(s, n=1):for i in range(n):target = list(s)res = []while target:k = random.randint(0, len(target) - 1)res.append(target.pop(k))return res# 3. 發(fā)牌
def del_cards():# 3.1 確定玩家a = input("請輸入玩家1號的名字:")b = input("請輸入玩家2號的名字:")c = input("請輸入玩家3號的名字:")# 存放牌r = {}r[a],r[b],r[c] = [],[],[]# 3.2 洗牌new_cards = fy_shuffle(cards,3)# 3.3 發(fā)牌for i in range(17):r[a].append(new_cards.pop())r[b].append(new_cards.pop())r[c].append(new_cards.pop())# 3.4 選地主d = random.sample((a,b,c),1)[0]print(f"這一輪的地主是:")r[d].extend((new_cards.pop(),new_cards.pop(),new_cards.pop()))print(f"[{a}]這一輪的牌是:[{' '.join(r[a])}]\n")print(f"[]這一輪的牌是:[{' '.join(r[b])}]\n")print(f"[{c}]這一輪的牌是:[{' '.join(r[c])}]\n")# 4.啟動游戲
del_cards()