Re: 你们最后复制了什么东西

楼主: gggiantguy (莫笑)   2024-12-22 23:10:06
import random
from copy import deepcopy
def member_shuffle(input_list) :
tmp_list = deepcopy(input_list)
random.shuffle(tmp_list)
return tmp_list
def member_move(input_list) :
step = random.randint(1,len(input_list)-1)
return (input_list + input_list)[step:step+len(input_list)]
member_list = ['a','b','c','d','e','f']
shuffled_member_list = member_shuffle(member_list)
moved_member_list = member_move(shuffled_member_list)
for member in member_list :
give_to = moved_member_list[shuffled_member_list.index(member)]
print('{} 送礼给 {}'.format(member,give_to))
输出:
a 送礼给 b
b 送礼给 a
c 送礼给 e
d 送礼给 f
e 送礼给 c
f 送礼给 d
理科圣诞节要交换礼物这么麻烦
不能线上用个抽签系统就好吗
作者: Firstshadow (IamCatづミ'_'ミづ)   2024-12-22 23:11:00
炫耀三件事: 1.有朋友抽 2.会写代码 3.会py
作者: sustainer123 (caster)   2024-12-22 23:13:00
这种简单功能丢给chatgpt就好了

Links booklink

Contact Us: admin [ a t ] ucptt.com