Last active
June 28, 2019 16:49
-
-
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 ⌨️🎉
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
import random | |
participants = ["Lena", "Seth", "Paul", "Suz", "Nina", "Burke", "Todd"] | |
print(f"{random.choice(participants)} is taking notes.") |
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.")
Thanks @nnja!
These examples are really helpful !
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
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 ,