Question

Making a Secret Santa I need a Python program that does the following: 1 - You...

Making a Secret Santa

I need a Python program that does the following:

1 - You can input the amount of people being entered into the Secret Santa

2 - Person1 does not get Person2, and vis versa.

3 - Person3 does not get Person4, and vis versa.

4 - Person5 does not get Person6, and vis versa.

5 - Person7 does not get Person8, and vis versa.

6 - When the random selection with the above conditions are complete, the program then exports a text file for every Person with the Person they are selected to buy a gift for.

7 - Each Person's file is titled (Their name).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import copy

from random import randint

def secret_santa(names):

my_list = names

choose = copy.copy(my_list)

result = []

for i in names:

names = copy.copy(my_list)

fi = open(i + ".txt", "w+")

names.pop(names.index(i))

index=randint(0,len(choose)-1)

while(index == my_list.index(i) or index == (my_list.index(i) + 1) or index == (my_list.index(i) - 1)):

index=randint(0,len(choose)-1)

chosen = choose[index]

fi.write(chosen)

result.append((i,chosen))

choose.pop(choose.index(chosen))

fi.flush()

fi.close()

return result

def main():

names = ['Person 1','Person 2','Person 3','Person 4', 'Person 5','Person 6','Person 7','Person 8']

res = secret_santa(names)

for i in range (0, len(res)):

print (res[i])

main()

************************************************************** SCREENSHOT *********************************************************

Files : main.py saved 1 import copy from random import randint main.py - Person 1.txt Python 3.7.4 (default, Jul 9 2019, 00:0

Add a comment
Know the answer?
Add Answer to:
Making a Secret Santa I need a Python program that does the following: 1 - You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Devlop a python program as simple as possible: Make sure the program run properly and Incude...

    Devlop a python program as simple as possible: Make sure the program run properly and Incude the ouput with the program.Thanks. Write a program to help determine the likelihood of winning the lottery. People pick six integers from 1 to 59, inclusive. Six lottery numbers are selected at random from the same range. If a person's six numbers match the lottery-selected numbers, the person wins a large cash prize. If the user matches any five of the six lottery-selected numbers,...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

  • i need help making this program the skeleton of the code is below: //Include the following #include <iostream> #...

    i need help making this program the skeleton of the code is below: //Include the following #include <iostream> #include <string> #include <fstream> //you must include this library if you wish to do file i/o using namespace std; /********************************************************* //Following is the declaration of a order record **********************************************************/ class order_record { public: string cell_number; string item_number; double quantity; double price; int processing_plant; double tax_rate; double order_tax; double net_cost; double total_cost; }; //Prototypes for your functions: input, output, and process will go...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions...

    NOTE: LANGUAGE IS PYTHON CS160 Computer Science Lab 17 Objectives Work with dictionaries Work with functions Work with files Overview This lab will have you store the birthdays for a group of people. This program will store the information with the focus on the date of the month and not on the individual. The point of this program is to be able to see who has a birthday on a given day or to create a table of birthdays, in...

  • Write a program named text_indexing.c that does the following: Reads text and stores it as one...

    Write a program named text_indexing.c that does the following: Reads text and stores it as one string called text. You can read from a file or from the user. (In my implementation, I read only one paragraph (up to new line) from the user. With this same code, I am able to read data from a file by using input redirection (executable < filename) when I run the program. See sample runs below). You can assume that the text will...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT