I'm a university student and I'm taking a python programming course for beginners.
I have this homework of creating a Lottery program with a coupon.
first, I had to create my own coupon that includes 6 numbers which I must select from 1 to 49, and then make a draw of 100000 times
and then I'm stuck in this requirement:
Calculate the chance of 3, 4, 5, and 6 match-up of your own coupon
I'm a little bit lost since this is not my expertise, but here is my attempt:
n = 100000
results = []
for i in range(n):
r = random.choice([7, 16, 21, 42, 40, 39])
results.append(r)
r = "myCoupon"
n7 = results.count("3, 4, 5, 6")
n16 = results.count("3, 4, 5, 6")
n21 = results.count("3, 4, 5, 6")
n42 = results.count("3, 4, 5, 6")
n40 = results.count("3, 4, 5, 6")
n39 = results.count("3, 4, 5, 6")
for k in range(1,50):
print("%i times %i (%.3f)" % (results.count(k), k, results.count(k)*100/n))
Is this attempt right?
n7 = results.count("3, 4, 5, 6")
n16 = results.count("3, 4, 5, 6")
n21 = results.count("3, 4, 5, 6")
n42 = results.count("3, 4, 5, 6")
n40 = results.count("3, 4, 5, 6")
n39 = results.count("3, 4, 5, 6")
Aucun commentaire:
Enregistrer un commentaire