You are on page 1of 3

#!

/usr/bin/env python
import random
LOTTMAX = 7
LOTT649 = 6
class LotteryNumber():
"""Play specified lottory
"""
def __init__(self, numbers=7):
self.number = numbers
def pick_numbers(self, low = 1, high = 49):
number = self.number
values = []
for num in range(number):
r = random.randrange(low, high)
while r in values:
r = random.randrange(low, high)
values.append(r)
return values
def checkNumbers(numberlists, hit, lotttype):
drawmax = {(3,0):5, (3,1):20, (4,0):20, (5,0):0.05, (6,0):0.04, (6,1):0.04,
(7,0):0.87}
draw649 = {(2,1):5, (3,0):10, (4,0):0.09, (5,0):0.0475, (5,1):0.0575, (6,0):
0.805}
lottdraw = { LOTTMAX:drawmax, LOTT649:draw649}
matches = []
matchb = []
mainnumbers = hit[:lotttype]
bonus = hit[lotttype]
for i in numberlists:
if len(i) != lotttype:
print "%s does not have required %d numbers" % ("-".join(i), lotttyp
e)
continue
for n in i:
nval = str(int(n))
if nval in mainnumbers:
matches.append(n)
if nval == bonus:
matchb.append(n)
lm = len(matches)
lb = len(matchb)
if (lm, lb) in lottdraw[lotttype].keys():
prize = lottdraw[lotttype][(lm,lb)]
if prize > 1:
BINGO = "You won %d dollars" % prize
else:
BINGO = "BINGO, BINGO!! You won %.2f%% of the jackpot!" % (prize
*100)
else:
BINGO = "Oops..."
print "%20s: match %d: %-20s bonus: %d: %s" % ("-".join(i), len(matches
), "-".join(matches), len(matchb), BINGO)
matches = []
matchb = []
def usage():
print "Usage: lott.py [-g NumberOfTickes | -x FileToCheck |-t Type]"
print " Type can be max or 649, default plays LottMax, i.e. generates 7-num
ber pair"
if __name__ == "__main__":
splitter = "-"
GENERATE = False
CHECK = False
lotttype = LOTTMAX
import sys, getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "g:x:t:")
if len(opts) == 0:
usage()
sys.exit()
for o, a in opts:
if o == "-g":
GENERATE = True
tickets = int(a)
if o == "-x":
CHECK = True
NUMFILE = a
if o == "-t":
type = a
if "m" in type.lower():
lotttype = LOTTMAX
if "6" in type.lower():
lotttype = LOTT649
except getopt.GetoptError:
usage()
sys.exit()
#tickets = int(sys.argv[1])
if GENERATE:
generator = LotteryNumber(lotttype)
for i in range(tickets):
#winning_number = LotteryNumber()
#print winning_number
oneticket = generator.pick_numbers()
oneticket.sort()
oneticket = map(lambda x: str(x), oneticket)
print "-".join(oneticket)
if CHECK:
import re
numlists = map(lambda x: re.split('\W+',x.strip()), filter(lambda x: x[0
] != "#", open(NUMFILE, "rU").readlines()))
jackpot = None
while not jackpot:
nowinnumbers = str(lotttype + 1)
try:
print "check number list in %s, with %d main numbers and %d bonu
s numbers" % (NUMFILE, lotttype, 1)
jackpot = raw_input("Please input winning numbers separated by s
pace, bonus number last one:\n").split()
except:
print "You should input %s numbers" % nowinnumbers
jackpot = None
checkNumbers(numlists, jackpot, lotttype)

You might also like