[Tutor] powerball
Marilyn Davis
marilyn at deliberate.com
Thu Jun 12 19:12:20 CEST 2008
On Wed, June 11, 2008 9:42 pm, max baseman wrote:
> hello and thank you everyone for your help. I apologize for my ignorance
> when it came to knowledge of what the powerball is it is not as wide
> spread as i had thought it was
>
> the powerball is a form of lottery their are 5 numbers between 1 and 55,
> and then their is the powerball between 1 and 42 players win different
> amounts of money depending on how many numbers they had right the program
> i wrote uses the number 146107962 as the amount of tickets in play i
> found this number on the powerball stat as the probability of getting
> jackpot 1 / 146107962 included is the finished and working script if
> anyone would like to use or play with it.
>
Hi Max,
The program looks great. You're getting real pythonic. Since you posted
it, I'll add some comments to help you spiff it up and make it faster.
Again, I'll use the > for comments:
from random import randrange # for creating random numbers
wins=0 # to see how many people would win
win=[] # the winning numbers go here
count=0
> You don't need count=0. Python sets the whole thing up for you
> with just that "for":
for count in range(5): # powerball uses 5 numbers
win.append(randrange(55)+1)
powerball=randrange(42)+1
count=0
while count != 146107962: # point of information useing for count in
range(146107962) will overlaoad with this large a number
> Then you might like xrange(big_number). It generates the numbers,
> one at a time.
numbers=[] # guesses
count2=0
for count2 in range(5):
number=randrange(55)+1
> With randrange, you can get duplicates. You can get
> [23, 2, 14, 23, 2] which I'm guessing can't
> happen in a real powerball game. (I don't know powerball either.)
> You might like the sample() function in the random library.
if number in win: # if the number is in the winning numbers continue
numbers.append(number)
else:
print "lose" # else quite while ahead
break
> There you went to the next player. It's a good place
> for a comment.
numbers.sort()
> You don't seem to need those numbers sorted.
win.sort()
> Since win is not changing, you might want to sort it only once,
> back when you made that list.
ball=randrange(42)+1 #picks the powerball
if ball == powerball:
print "win"
wins=wins+1
> else? it's quiet.
count=count+1
print
print wins,"winners with", win, powerball
> What happens wrong? I didn't run it? Does it just fall quiet for a
> while? You might try putting in some extra print statements to see
> what is exactly happening.
> Are you a student? What grade?
>
>
> seeing as i have left the python mailing list in the past any comments or
> ideas would be appreciated if sent to this email - thank you
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list