Board logo

標題: 亂數 (四) - 抽撲克牌 [打印本頁]

作者: tonyh    時間: 2022-7-16 14:50     標題: 亂數 (四) - 抽撲克牌

本帖最後由 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])    #前五張
複製代碼

作者: 李沛昂    時間: 2022-7-16 15:05

  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=" ")
複製代碼

作者: 王捷恩    時間: 2022-7-16 15:08

  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())
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2