random.shuffle()
random.sample()
撲克牌洗牌:
輸出結果:
撲克牌洗牌:
import random
cards = list(range(1,53)) ##len(cards) = 52
random.shuffle(cards)
num=13
card1 = cards[0:num]
card2 = cards[num:num*2]
card3 = cards[num*2:num*3]
card4 = cards[num*3:]
print(“card1:”,card1)
print(“card2:”,card2)
print(“card3:”,card3)
print(“card4:”,card4)
推薦hahow線上學習python: https://igrape.net/30afN
近期留言