一副扑克牌,有多少种洗牌可能呢?
方法一:
cards=[]
for i in range(1,55):
cards.append(i)
print("洗牌之前:",cards)
import random
a = []
for i in range(2, 11):
a.append(f'黑桃{i}')
a.append(f'梅花{i}')
a.append(f'红桃{i}')
a.append(f'方块{i}')
k = 'JQKA'
for i in k:
a.append(f'黑桃{i}')
a.append(f'梅花{i}')
a.append(f'红桃{i}')
a.append(f'方块{i}')
a.append('大王')
a.append('小王')
print('洗牌之前:', a, sep='\n')
for i in range(100):
k = random.randint(0, 53)
m = random.randint(0, 53)
a[k], a[m] = a[m], a[k]
print('洗牌之后:', a, sep='\n')
也可以使用第二种方法
import random
cards=[]
for i in range(1,55):
cards.append(i)
print("洗牌之前:",cards)
random.shuffle(cards)
print("洗牌之后",cards)