python实现2024春晚魔术

#央视龙年春晚 魔术《守岁共此时》,邀请全国观众一起见证奇迹发生

python实现2024春晚魔术

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import random
cards=[1,2,3,4]
random.shuffle(cards)
print("打乱后的卡牌:",cards)
cards=cards+cards
print("撕开的卡牌:",cards)
name=int(input("姓名有几个字?"))
for i in range(name):
cards.append(cards.pop(0))
print("当前卡牌;",cards)
top_three_cards=cards[:3]
else_cards=cards[3:]
insert_index=random.randint(1,5)
cards=else_cards[:insert_index]+top_three_cards+else_cards[insert_index:]
print("当前卡牌;",cards)
top_card=cards.pop(0)
region=input("你是南方人还是北方人?(“南”、“北”?)")
if region == "南":
insert_count = 1
elif region == "北":
insert_count = 2
else:
insert_count = 3
top=cards[:insert_count]
else_cards=cards[insert_count:]
insert_index=random.randint(0,len(else_cards)-1)
cards=else_cards[:insert_index]+top+else_cards[insert_index:]
print("当前卡牌;",cards)
gender=input("“男”/“女”?")
if gender == "男":
take_count = 1
elif gender == "女":
take_count = 2
for i in range(take_count):
cards.pop(0)
for i in range(len("见证奇迹的时刻")):
cards.append(cards.pop(0))
while True:
cards.append(cards.pop(0))
cards.pop(0)
if len(cards)==1:
break
else:
print(cards)
print("你刚才藏起来的牌是:",top_card)
print("你手里剩下的牌是:",cards[0])
print("按任意键结束并关闭页面")
input() # 等待用户输入

python实现2024春晚魔术
https://ianwusb.blog/2024/03/02/python实现2024春晚魔术/
作者
Ianwusb
发布于
2024年3月2日
许可协议