add powerball
This commit is contained in:
parent
7542937fa6
commit
a5efb9a553
60
pwrball.py
Executable file
60
pwrball.py
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
# Generate one random powerball lotto number that is not an avoided number in the avoid.csv file.
|
||||||
|
# It simply redraw a number if the previous drawn number is an avoided number.
|
||||||
|
|
||||||
|
import secrets
|
||||||
|
import logging
|
||||||
|
import csv
|
||||||
|
|
||||||
|
def meganumber():
|
||||||
|
|
||||||
|
picks = []
|
||||||
|
# the mega million valid numbers are between 1 to 69 inclusive
|
||||||
|
choices = list(range(1,70))
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
logging.debug("choices are: %s", choices)
|
||||||
|
pick = secrets.choice(choices)
|
||||||
|
choices.remove(pick)
|
||||||
|
picks.append(pick)
|
||||||
|
|
||||||
|
logging.debug("choices left: %s", choices)
|
||||||
|
logging.debug("first five numbers: %s", picks)
|
||||||
|
picks.sort()
|
||||||
|
|
||||||
|
# the mega ball number is from 1 to 26
|
||||||
|
pick = secrets.choice(list(range(1,27)))
|
||||||
|
picks.append(pick)
|
||||||
|
|
||||||
|
return picks
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
# logging.basicConfig(level=logging.DEBUG, format = "[%(levelname)s] (%(threadName)-10s) %(message)s",)
|
||||||
|
logging.basicConfig(level=logging.INFO, format = "[%(levelname)s] (%(threadName)-10s) %(message)s",)
|
||||||
|
|
||||||
|
avoid = []
|
||||||
|
with open("avoid.csv", "r") as f:
|
||||||
|
reader = csv.reader(f)
|
||||||
|
for row in reader:
|
||||||
|
introw = []
|
||||||
|
for num in row:
|
||||||
|
introw.append(int(num))
|
||||||
|
avoid.append(introw)
|
||||||
|
|
||||||
|
for item in avoid:
|
||||||
|
logging.debug("before: %s", item)
|
||||||
|
item[0:5] = sorted(item[0:5])
|
||||||
|
logging.debug("after: %s", item)
|
||||||
|
|
||||||
|
pickone = meganumber()
|
||||||
|
while pickone in avoid:
|
||||||
|
print("the picked number is in the avoid list: %s, regenerate", pickone)
|
||||||
|
pickone = meganumber()
|
||||||
|
|
||||||
|
print(pickone)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user