写一段“三张扑克”游戏的python代码
时间: 2023-03-13 13:30:34 浏览: 80
# 定义一个函数,用于从牌堆中抽取三张牌,并返回抽取的牌
def draw_three_cards():
import random
# 定义一个牌堆
cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
# 从牌堆中抽取三张牌
drawn_cards = random.sample(cards, 3)
# 返回抽取的牌
return drawn_cards# 调用函数,获取抽取的牌
my_cards = draw_three_cards()
# 输出抽取的牌
print(my_cards)
相关问题
写一段“三张扑克”的python代码
cards = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]for i in range(3):
card_index = random.randint(0, len(cards) - 1)
print(cards[card_index])
帮我写一段斗地主python代码
好的,以下是一段简单的斗地主 Python 代码:
```python
import random
# 定义扑克牌
poker = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2', '小王', '大王']
# 定义洗牌函数
def shuffle_poker():
random.shuffle(poker)
# 定义发牌函数
def deal_poker():
shuffle_poker()
player1 = poker[:17]
player2 = poker[17:34]
player3 = poker[34:51]
bottom = poker[51:]
return player1, player2, player3, bottom
# 测试发牌函数
player1, player2, player3, bottom = deal_poker()
print('玩家1的牌:', player1)
print('玩家2的牌:', player2)
print('玩家3的牌:', player3)
print('底牌:', bottom)
```
希望能对你有所帮助!
阅读全文