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