春晚刘谦第二个魔术原理

效果

 

代码

import random

name_num = int(input("名字几个字:"))
n_or_s = int(input("南方人还是北方人(南方输入1,北方输入0):"))
man_or_woman = int(input("输入性别(男性输入1,女性输入0):"))

print(f"你的名字是{name_num}个字")
print("南方人" if n_or_s == 1 else "北方人")
print("男生" if man_or_woman == 1 else "女生")

cards = random.sample(range(1, 15), 4)
print(f"随机抽取四张扑克牌 -> {cards}")
random.shuffle(cards)
print(f"洗牌后的扑克牌 -> {cards}")
cards += cards[::1]
print(f"对折撕开再与原牌组合并 -> {cards}")

temp_list = cards[0:name_num]
cards = cards[name_num:] + temp_list
print(f"名字数量之后重新组合的牌组 -> {cards}")

temp_list = cards[0:3]
cards = cards[3:]
insert_index = 2
cards[insert_index + 1:insert_index + 1] = temp_list
print(f"插入最上面三张牌后的牌组 -> {cards}")

hide_card = cards.pop(0)
print(f"最上面被藏起来的扑克牌 -> {hide_card}")
print(f"最上面被藏起来的牌被拿走后的牌组 -> {cards}")

if n_or_s == 1:
    temp_list = cards.pop(0)
    insert_index = 1
else:
    temp_list = cards[0:2]
    cards = cards[2:]
    insert_index = 1
cards[insert_index + 1:insert_index + 1] = temp_list
print(f"南方人插入最上面一张牌后的牌组 -> {cards}" if n_or_s == 1 else f"北方人插入最上面一张牌后的牌组 -> {cards}")

cards = cards[1:] if man_or_woman == 1 else cards[2:]
print(f"男生扔掉最上面一张牌后的牌组 -> {cards}" if man_or_woman == 1 else f"女生扔掉最上面两张牌后的牌组 -> {cards}")

for _ in range(7):
    first_num = cards.pop(0)
    cards.append(first_num)
print(f"见证奇迹的时刻 -> {cards}")

while len(cards) > 1:
    cards.append(cards[0])
    cards = cards[2:]
    
print(f"最后一张好运牌 -> {cards[0]}")
print(f"被藏起来的牌 -> {hide_card} 最后的好运牌 -> {cards[0]}")