54张扑克牌发给三个人,最后留三张,麻烦用python写出这个代码
时间: 2023-03-10 20:46:33 浏览: 102
答案:import random# 创建一副扑克牌
deck = [i for i in range(1, 55)]# 洗牌
random.shuffle(deck)# 发牌,每人发18张牌
player1 = deck[0:18]
player2 = deck[18:36]
player3 = deck[36:54]# 剩余三张牌
remaining_cards = deck[54:]print("发牌结果:")
print("玩家1:", player1)
print("玩家2:", player2)
print("玩家3:", player3)
print("剩余牌:", remaining_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代码
# 定义一个函数,用于从牌堆中抽取三张牌,并返回抽取的牌
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)