-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLotto_Matches_Calculator.py
47 lines (31 loc) · 1.08 KB
/
Lotto_Matches_Calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import random
def put_in_commas(num):
if len(num) < 4:
return num
return str(put_in_commas(num[:-3])) + ',' + str(num[-3:])
print('\nHow many lotto simulations do you want to take place? (Input Below)')
itterations = int(input())
print('\nFrom a simulation of {} Lotto Draws, You got:'.format(
put_in_commas(str(itterations))))
matches = {2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
numbers = sys.argv[1:]
lucky_nums = set()
for number in numbers:
lucky_nums.add(int(number))
for i in range(itterations):
lotto_numbers = set(random.sample(range(1, 48), 6))
match = lotto_numbers & lucky_nums
if len(match) > 1:
matches[len(match)] += 1
prob = []
new_matches = []
for i in range(2, 7):
try:
prob.append(put_in_commas(str(itterations // matches[i])))
except ZeroDivisionError:
prob.append('?')
finally:
new_matches.append(put_in_commas(str(matches[i])))
print(' {} Matches {:>{}} times => You have a 1 in {} chance of winning'.format(
i, new_matches[i - 2], len(new_matches[0]), prob[i - 2]))