返回列表 發帖

亂數 (四) - 抽撲克牌

本帖最後由 tonyh 於 2022-7-16 14:52 編輯

  1. from random import shuffle

  2. suit=["♠️", "♥️", "♦️", "♣️"]
  3. order=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
  4. deck=[]
  5. for i in suit:
  6.     for j in order:
  7.         deck.append(i+j)

  8. shuffle(deck)

  9. for i in range(5):
  10.     print(deck.pop())    #後五張
  11.     #print(deck[i])    #前五張
複製代碼

  1. from random import *
  2. suit=["♠️", "♥️", "♦️", "♣️"]
  3. order=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
  4. deck=[]
  5. for i in suit:
  6.     for j in order:
  7.         deck.append(i+j)
  8. shuffle(deck)
  9. for i in range(5):
  10.     print(deck[i],end=" ")
  11. print()
  12. for i in range(5):
  13.     print(deck.pop(),end=" ")
複製代碼

TOP

  1. from random import shuffle
  2. suit=["♠️", "♥️", "♦️", "♣️"]
  3. order=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
  4. deck=[]
  5. for i in suit:
  6.     for j in order:
  7.         deck.append(i+j)
  8. shuffle(deck)
  9. print(deck)
  10. for i in range(5):
  11.     print(deck.pop())
複製代碼

TOP

返回列表