Python3類比鬥地主發牌__Python

來源:互聯網
上載者:User

類比鬥地主發牌,牌共54張,

花色:黑桃('\u2660'),梅花('\u2663'),方塊('\u2665'),紅桃(‘\u2666’),種類為:A2-10JQK,大小王(X, x)    三個人,每個人17張牌,牌底留三張
   輸入斷行符號,列印第一個問的17張牌
   輸入斷行符號,列印第二個問的17張牌

   輸入斷行符號,列印第三個問的17張牌

import random as R
""" 實現一人一次隨機發17張牌""" def reduce(L, w):     for x in w:         L.pop(L.index(x))     return L L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'] H = ['\u2660', '\u2663', '\u2665', '\u2666'] P = ['X','x'] for x in H:     for y in L:         s = x + y         P.append(s) R.shuffle(P) i = 0 L2 = [] while i < 2:     if len(P) > 17:         w = R.sample(P, 17) # 從序列中選擇n個隨機且不重複的元素         L2.append(w)         P = reduce(P, w)         print(w)         input()     else:         break print(P)
import random as R"""上面代碼的簡單實現"""L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']L1 = ['X', 'x']L1.extend(map(lambda x: x+"\u2660", L))L1.extend(map(lambda x: x+"\u2663", L))L1.extend(map(lambda x: x+"\u2665", L))L1.extend(map(lambda x: x+"\u2666", L))R.shuffle(L1)print(L1[0:17])input()print(L1[17:34])input()print(L1[34:51])input()print(L1[51:])
import random as R"""一次一人發一張牌"""L = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']H = ['\u2660', '\u2663', '\u2665', '\u2666']w1 = []w2 = []w3 = []P = ['X','x']for x in H:    for y in L:        s = x + y        P.append(s)R.shuffle(P)i = 1while i <= 17:    w1.append(P.pop())    w2.append(P.pop())    w3.append(P.pop())    i += 1print(w1)input()print(w2)input()print(w3)input()print(P)



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.