随机生成一副扑克牌(去掉大小王),并分给4位牌手,每个选手13张,输出。
时间: 2024-05-06 20:16:49 浏览: 193
模拟一副扑克牌发牌4人
5星 · 资源好评率100%
下面是 Python 代码实现:
```python
import random
# 生成一副扑克牌
suits = ["♠", "♥", "♦", "♣"]
ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
deck = [rank + suit for suit in suits for rank in ranks]
# 洗牌
random.shuffle(deck)
# 分发给4位牌手
players = [[], [], [], []]
for i in range(13):
for j in range(4):
players[j].append(deck[i * 4 + j])
# 输出
for i, player in enumerate(players):
print("玩家%d:" % (i+1), player)
```
输出结果类似于:
```
玩家1: ['A♥', '10♥', 'K♣', '3♠', '7♦', '2♦', '4♣', '10♦', 'Q♥', '5♠', '4♥', '8♣', '6♦']
玩家2: ['7♥', 'Q♣', '3♦', '8♥', '2♣', '4♠', '5♥', '5♣', '2♥', '9♦', 'K♦', 'J♥', '9♣']
玩家3: ['J♠', 'Q♦', '8♦', '6♠', '7♠', 'K♥', '6♣', '9♥', '3♣', 'A♦', '10♠', '4♦', 'J♣']
玩家4: ['5♦', 'A♣', '6♥', '9♠', '8♠', 'J♦', '7♣', 'K♠', 'Q♠', '3♥', '2♠', '10♣', 'A♠']
```
阅读全文