Today is the election of the governor of Tokyo!
This year is already a ready race, and many people think that it doesn't matter who they vote for, and the turnout may drop.
https://www.amazon.co.jp/dp/4887597126 Young people lose 400,000 yen because they don't go to elections !? (Discover handbook) (Japanese) New book
There are books, but
When it comes to Only those with a support base will have an advantage, In other words, ** boring politics will continue **, so I definitely want to vote.
As you can see in the above books, if you don't have a person you want to choose, you can roll the pencil and choose it.
My goal is
Because it is.
However, there are times when there are people who do not want to choose even if there are no people who want to choose.
Give me a list of candidates and they will choose one of them We have prepared a program such as.
given_lottery.py
import secrets
import sys
def draw_lots(data=None):
if data is None:
return -1
lot_member = data.split(',')
r = secrets.randbelow(len(lot_member))
return lot_member[r]
if __name__ == '__main__':
args = sys.argv
print(draw_lots(args[1]))
That's about it.
It will be a movement such as.
** Addition **
In the comment, I was pointed out that there is a choice function.
That's why refactoring.
import secrets
import sys
def draw_lots(data=None):
if data is None:
return -1
return secrets.choice(data.split(','))
if __name__ == '__main__':
args = sys.argv
print(draw_lots(args[1]))
It was refreshing.
The source file is https://github.com/atworks/given-lottery I put it in.
later
> python .\given_lottery.py a,b,c,d,e
e
If you pass a string separated by commas like, randomly select one and output it.
I want to have a good voting life.
Recommended Posts