jackrabbitslim
jackrabbitslim

Reputation: 1

Lottery winning chances python

I'm trying to create a lottery simulation to see what are the chances of winning. I begin very simply : my program should run the lottery x times, and then to find the probability of winning should divide the numbers wins by the number of loss. My problem is how to count wins and store them ? The code for now is:

from random import randint

for i in range (1,1001):
    a = randint(1,1000)
    print (a)
    if a == 1:

from there i don't know what to do ???

what to do to store 1 (the winning ticket) each time it occur in order to estimate the chances of wining ?

Upvotes: 0

Views: 1700

Answers (1)

victor
victor

Reputation: 1644

Store the counts in a variable.

from random import randint

winCount = 0

for i in range (1,1001):
    a = randint(1,1000)
    print (a)
    if a == 1:
        winCount += 1

winProportion = winCount / 1000

Upvotes: 1

Related Questions