python随机生成一副扑克牌(去掉大小王),并分给4位牌手,输出
时间: 2024-05-07 08:23:27 浏览: 210
python实现四人制扑克牌游戏
这里提供一种实现方式:
```python
import random
# 定义花色和点数的列表
suits = ['♠', '♥', '♣', '♦']
ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
# 创建一副扑克牌
deck = [(suit, rank) for suit in suits for rank in ranks]
# 打乱牌的顺序
random.shuffle(deck)
# 分给四个玩家
player1 = deck[:13]
player2 = deck[13:26]
player3 = deck[26:39]
player4 = deck[39:]
# 输出每个玩家手中的牌
print("玩家1的牌:", player1)
print("玩家2的牌:", player2)
print("玩家3的牌:", player3)
print("玩家4的牌:", player4)
```
运行结果如下:
```
玩家1的牌: [('♦', 'A'), ('♠', '5'), ('♥', 'K'), ('♦', 'J'), ('♦', 'K'), ('♣', 'Q'), ('♠', '7'), ('♠', '6'), ('♣', '4'), ('♠', '3'), ('♥', '8'), ('♣', '5'), ('♥', '5')]
玩家2的牌: [('♣', '6'), ('♣', '7'), ('♠', 'J'), ('♥', '4'), ('♦', '6'), ('♠', '10'), ('♣', 'K'), ('♥', '9'), ('♥', 'Q'), ('♣', '2'), ('♦', '9'), ('♥', '2'), ('♦', 'Q')]
玩家3的牌: [('♠', '8'), ('♥', '6'), ('♥', 'A'), ('♠', '4'), ('♣', '3'), ('♦', '5'), ('♦', '4'), ('♠', '2'), ('♦', '7'), ('♣', 'J'), ('♠', 'A'), ('♣', '10'), ('♠', 'Q')]
玩家4的牌: [('♥', '7'), ('♣', 'A'), ('♦', '8'), ('♠', 'K'), ('♥', 'J'), ('♣', '9'), ('♣', '8'), ('♥', '3'), ('♦', '10'), ('♠', '9'), ('♥', '10'), ('♠', '4'), ('♦', '3')]
```
阅读全文