Skip to content

Instantly share code, notes, and snippets.

@nnja
Last active June 28, 2019 16:49
Show Gist options
  • Save nnja/0345f72f9ce8b5f1eee8162ffa3e2857 to your computer and use it in GitHub Desktop.
Save nnja/0345f72f9ce8b5f1eee8162ffa3e2857 to your computer and use it in GitHub Desktop.
Python script to select a random person to take notes in a meeting ⌨️🎉
import random
participants = ["Lena", "Seth", "Paul", "Suz", "Nina", "Burke", "Todd"]
print(f"{random.choice(participants)} is taking notes.")
@CooperFLe
Copy link

@tbalz2319 in a meeting that large, people should be taking their own notes. You can’t reasonably expect a single random person to be able to keep relevant notes for 100+ individuals.

@tbalz2319
Copy link

Yes true , just throwing that in as an example. It would still work for 2-10 people and I figured editing a text file would be easier than modifying Python code and working with that “” and ,

@nnja
Copy link
Author

nnja commented Jun 21, 2019

@tbalz2319

Your code doesn't close the file. The clearer and more Pythonic way to achieve the same result would use a context manager, like this:

# Reading names from a file, one name per line.
import random

with open("people.txt", "r") as names:
    participants = names.read().split()
    print(f"{random.choice(participants)} is taking notes.")

Or, if your main concern is not having to type quotes and commas, just just a multi-line string, like so:

# Using a non-comma seperated multi-line string
import random

participants = """
Lena
Seth
Paul
Suz
Nina
Burke
Todd
"""
print(f"{random.choice(participants.split())} is taking notes.")

@tbalz2319
Copy link

Thanks @nnja!

These examples are really helpful !

@cdadhecodes
Copy link

Saw this notice in an <a href=''https://Holbertonschool.com> project</a> and thought it was interesting. I am having to come up with a project for githib and thought I would take a peak here. Best wishes for you. gDavis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment