DAY 11 - Organize a Secret Santa Game in your organization using a Python Script
DAY 11 - Organize a Secret Santa Game in your organization using a Python Script
Secret Santa Rule:
##################
The basic concept of the Secret Santa game is simple. All of the participants’ names are placed into a hat, box, etc. and mixed up. Each person then chooses one name from the box, but doesn’t tell anyone which name was picked. He/she is now responsible for buying a gift for the person selected.
When the Secret Santa wraps his/her gift, he/she should label it with the recipient’s name but doesn’t indicate whom the present is from. (Remember, most of the fun is in the secrecy.)
All the gifts are then placed in a general area for opening at a designated time. When the gift-giving time arrives, each recipient finds his/her gift and must guess who their Secret Santa is. If they can’t guess, their Secret Santa eventually confesses.
Gone are the old days when we used to ask each particpant to pick a name from the box. Now it's a digital world. So it is wise to have a plan in place to make the best use of the time and resources !!!!
This time we have automated "Secret Santa Game" to save time and efforts. Yippee!!!
import random
import pandas as pd
import numpy as np
ss_keys = []
ssc_values = []
print ('Enter email address of participants in this format - rakesh.ranjan@xyz.com,rupesh.kumar@xyz.com ')
input_string = input ("Enter participants email address separated by comma ")
#to convert input_string into a list
ss_participants = input_string.split(",")
ss_child = input_string.split(",")
#secret santa list .......converting each character to lowercase
ss_participants = list(map(lambda x:x.lower(),ss_participants))
#secret santa child list. Keep on removing name of child from the list after each iteration
ss_child = list(map(lambda x:x.lower(),ss_child))
print('Total Count Of Participants: ' , len(ss_participants))
print ('###############################################################')
#iteration for each participant to find his/her secret santa child
for i in ss_participants:
msg = ""
email = i
#logic to extract first name of secret santa from email_id
ss_email_breakup_list = email.split(".")
ss_name = ss_email_breakup_list[0].capitalize()
msg = 'Hello ' + ss_name + '.' + ' '
#pick a random name. so we are using function# "random.choice" to find secret santa - child
secret_santa_child = random.choice(ss_child)
#written logic to exclude secret santa name so that he/she won't buy a gift for himself/herself
while secret_santa_child == email:
secret_santa_child = random.choice(ss_child)
#remove secret santa - child name from the list so that same person won't receive the gift more than once
ss_child.remove(secret_santa_child)
#Keep adding a Secret santa name in the list - test_keys
ss_keys.append(email)
##Keep adding a corresponding value of Secret santa child name in the list - test_values
ssc_values.append(secret_santa_child)
#logic to extract first name of secret santa - child from email_id
ssc_email_id_breakup_list = secret_santa_child.split(".")
ssc_name = ssc_email_id_breakup_list[0].capitalize()
msg = msg + 'You are Secret Santa for :' + ssc_name
print(msg)
#consolidated list of secret santa and his/her child
#print(ss_keys)
#print(ssc_values)
res = {ss_keys[i]: ssc_values[i] for i in range(len(ss_keys))}
print ('###############################################################')
print("Consolidated list of Secret Santa and his/her Secret Santa Child")
print ('###############################################################')
print(res)
#RR #Day11 #Python #SecretSantaGame #HappyLearning #WeLearnEveryday
Secret Santa Rule:
##################
The basic concept of the Secret Santa game is simple. All of the participants’ names are placed into a hat, box, etc. and mixed up. Each person then chooses one name from the box, but doesn’t tell anyone which name was picked. He/she is now responsible for buying a gift for the person selected.
When the Secret Santa wraps his/her gift, he/she should label it with the recipient’s name but doesn’t indicate whom the present is from. (Remember, most of the fun is in the secrecy.)
All the gifts are then placed in a general area for opening at a designated time. When the gift-giving time arrives, each recipient finds his/her gift and must guess who their Secret Santa is. If they can’t guess, their Secret Santa eventually confesses.
Gone are the old days when we used to ask each particpant to pick a name from the box. Now it's a digital world. So it is wise to have a plan in place to make the best use of the time and resources !!!!
This time we have automated "Secret Santa Game" to save time and efforts. Yippee!!!
import random
import pandas as pd
import numpy as np
ss_keys = []
ssc_values = []
print ('Enter email address of participants in this format - rakesh.ranjan@xyz.com,rupesh.kumar@xyz.com ')
input_string = input ("Enter participants email address separated by comma ")
#to convert input_string into a list
ss_participants = input_string.split(",")
ss_child = input_string.split(",")
#secret santa list .......converting each character to lowercase
ss_participants = list(map(lambda x:x.lower(),ss_participants))
#secret santa child list. Keep on removing name of child from the list after each iteration
ss_child = list(map(lambda x:x.lower(),ss_child))
print('Total Count Of Participants: ' , len(ss_participants))
print ('###############################################################')
#iteration for each participant to find his/her secret santa child
for i in ss_participants:
msg = ""
email = i
#logic to extract first name of secret santa from email_id
ss_email_breakup_list = email.split(".")
ss_name = ss_email_breakup_list[0].capitalize()
msg = 'Hello ' + ss_name + '.' + ' '
#pick a random name. so we are using function# "random.choice" to find secret santa - child
secret_santa_child = random.choice(ss_child)
#written logic to exclude secret santa name so that he/she won't buy a gift for himself/herself
while secret_santa_child == email:
secret_santa_child = random.choice(ss_child)
#remove secret santa - child name from the list so that same person won't receive the gift more than once
ss_child.remove(secret_santa_child)
#Keep adding a Secret santa name in the list - test_keys
ss_keys.append(email)
##Keep adding a corresponding value of Secret santa child name in the list - test_values
ssc_values.append(secret_santa_child)
#logic to extract first name of secret santa - child from email_id
ssc_email_id_breakup_list = secret_santa_child.split(".")
ssc_name = ssc_email_id_breakup_list[0].capitalize()
msg = msg + 'You are Secret Santa for :' + ssc_name
print(msg)
#consolidated list of secret santa and his/her child
#print(ss_keys)
#print(ssc_values)
res = {ss_keys[i]: ssc_values[i] for i in range(len(ss_keys))}
print ('###############################################################')
print("Consolidated list of Secret Santa and his/her Secret Santa Child")
print ('###############################################################')
print(res)
#RR #Day11 #Python #SecretSantaGame #HappyLearning #WeLearnEveryday
Comments
Post a Comment