Last active
November 21, 2021 23:14
-
-
Save Lokno/42755d897913fe5a94442ed34974601e to your computer and use it in GitHub Desktop.
Short python 3 script for randomly generating giftees for a gift exchange between 2 or more people.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
from sys import argv | |
from pathlib import Path | |
names = [] | |
if len(argv) == 2: | |
file_path = Path(argv[1]) | |
if not file_path.exists(): | |
print(f'File not found: {argv[1]:s}') | |
else: | |
with open(argv[1],'r') as f: | |
names = [n.rstrip().upper() for n in f.readlines() if n.rstrip() != ''] | |
n = len(names) | |
if n > 2: | |
shuffle(names) | |
for i in range(n): | |
name1 = names[i] | |
name2 = names[(i+1) % n] | |
print (f'{name1:s}\'s secret giftee is {name2:s}') | |
else: | |
print('List must contain more than 1 name') | |
else: | |
print(f' usage: {argv[0]:s} <input.txt>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment