#Python撲克牌的4種花色,撲克牌洗牌_2
import random
a1=[];a2=[];b1=[];b2=[];c1=[];c2=[];d1=[];d2=[]
card=random.sample(range(1,53),52)
for i in range(52):
if card[i]//13==1:f=”?心” #從word複製花色的圖形進去
elif card[i]//13==2:f=”?鑽”
elif card[i]//13==3:f=”?鏟”
else :f=”?花”
if card[i]%13== 0:p=”A”
elif card[i]%13==10:p=”J”
elif card[i]%13==11:p=”Q”
elif card[i]%13==12:p=”K”
else :p=str(card[i]%13+1) # %求餘數
if i%4 ==0:
a1.append(f)
a2.append(p)
if i%4 ==1:
b1.append(f)
b2.append(p)
if i%4 ==2:
c1.append(f)
c2.append(p)
if i%4 ==3:
d1.append(f)
d2.append(p)
print(“=一=*=二=*=三=*=四=”)
for j in range(13):
print(“%s%-2s “%(str(a1[j]),str(a2[j])),end=”*”)
print(“%s%-2s “%(str(b1[j]),str(b2[j])),end=”*”)
print(“%s%-2s “%(str(c1[j]),str(c2[j])),end=”*”)
print(“%s%-2s “%(str(d1[j]),str(d2[j])))
輸出結果:
近期留言