【Python】复现刘谦春晚魔术!

import random
# 名字长度 2-7 的自然数
name_length = 2
# 南方1 北方2 分不清3
north_south = 1
# 男1 女2
gender = 1

cards = [1, 2, 3, 4]
cards = cards + cards
print(cards)
# [1, 2, 3, 4, 1, 2, 3, 4]

# 将队头的name_length张插入队尾
for _ in range(name_length):
    cards.append(cards.pop(0))
print(cards)
# [3, 4, 1, 2, 3, 4, 1, 2]

# 将队头的三个元素 插入中间
top_three = cards[:3]
last_five = cards[3:]
# 随机生成插入位置
location = random.randint(1, 4)
cards = last_five[:location] + top_three + last_five[location:]
print(cards)
# [2, 3, 3, 4, 1, 4, 1, 2]

under_butt = cards.pop(0)
print("屁股下的牌:" + str(under_butt))
# 屁股下的牌:2

top_cards = cards[:north_south]
last_cards = cards[north_south:]
# 随机生成插入位置
location = random.randint(1, 7-north_south-1)
cards = last_cards[:location] + top_cards + last_cards[location:]
print(cards)

for _ in range(gender):
    cards.pop(0)
print(cards)

print("见证奇迹的时刻")
for _ in range(7):
    cards.append(cards.pop(0))
print(cards)

while len(cards) > 1:
    # 好运留下来
    cards.append(cards.pop(0))
    # 烦恼丢出去
    cards.pop(0)
    print(cards)

assert cards[0] == under_butt

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值