標題:
亂數 (四) - 抽撲克牌
[打印本頁]
作者:
tonyh
時間:
2022-6-18 16:54
標題:
亂數 (四) - 抽撲克牌
from random import shuffle
suit=["♠️", "♥️", "♦️", "♣️"]
order=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
deck=[]
for i in suit:
for j in order:
deck.append(i + j)
shuffle(deck)
for i in range(5):
print(deck.pop()) #後五張
#print(deck[i]) #前五張
複製代碼
作者:
郭詩瑜
時間:
2022-6-18 17:40
import random as r
suit=["♠️", "♥️", "♦️", "♣️"]
order=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
deck=[]
for i in suit:
for j in order:
deck.append(i+j)
r.shuffle(deck)
final = []
for i in range (5):
a = r.choice(deck)
final.append(a)
deck.remove(a)
print(f"{final}")
print(deck)
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2