I'm trying to make a Secret Santa program. Ideally the program should ask for at least three names, and afterwards the program asks if there are more names. If yes, open up another text field and add it to the list of names. If no, break the loop, create a separate list with the names inside it, shuffle the second list of names, and pair them up with a name from the original list.
For example, if John, Elliot, Sarah and Jenny put in their names and the program shuffled their names, it should output something like this:
[('John', 'Sarah'), ('Elliot', 'John'), ('Sarah', 'Jenny'), ('Jenny', 'Elliot')]
But instead I get something like:
[('John', 'John'), ('Elliot', 'John'), ('Sarah', 'Elliot'), ('Jenny', 'Jenny')]
Here's the code:
import sys
import random
names = []
class Santa:
#The class that takes the values, shuffles them, pairs and then displays them
def __init__(self, name):
self.turns = name
self.people = names
self.final = []
def sort_names(self):
random.shuffle(self.people)
for name in self.turns:
pair = (name, random.choice(self.people))
if pair[0] == [1]:
pair = (name, random.choice(self.people))
else:
self.final.append(pair)
def print_name(self):
input("\nNames are ready! Press Enter to show the names.")
print(self.final)
def main():
# The function asking for user input
name = input("\nType in your name. ")
names.append(name)
name = input("\nType in the next name. ")
names.append(name)
name = input("\nType in the next name. ")
names.append(name)
while True:
next = input("\nIs this everyone? Y/N ")
if next.upper() == "Y":
break
elif next.upper() == "N":
name = input("\nType in the next name. ")
names.insert(0, name)
else:
print("\nInvalid response, please try again.")
print(names)
start = Santa(names)
start.sort_names()
start.print_name()
input("\nRecord these, and press enter to quit.")
sys.exit()
main()