Last active 1722514789

Venezuelan_election_odds.py Raw
1>>> from random import randint
2# Number of voters
3>>> N = 10_058_774
4# Counter of occurrences
5>>> cnt = 0
6# Count how many occurrences we measure where the
7# shares of votes exactly match their rounded
8# representation to the first decimal digit
9>>> for _ in range(N):
10 # Share of votes to candidate A,
11 # as a random number between 30% and 70%
12... A = randint(round(0.3 * N), round(0.7 * N)) / N
13 # Share of votes to candidate C (others),
14 # as a random number between 1% and 10%
15... C = randint(round(0.01 * N), round(0.1 * N)) / N
16 # Share of votes to candidate B,
17 # 100% - votes(A) - votes(C)
18... B = 1 - A - C
19 # Get the values of A, B and C rounded to the
20 # first decimal
21... A_round = round(round(A/N, 3) * N)
22... B_round = round(round(B/N, 3) * N)
23... C_round = round(round(C/N, 3) * N)
24 # If the rounded representations of A, B and C
25 # match their actual values, increase the counter
26... if A == A_round and B == B_round and C == C_round:
27... cnt += 1
28...
29# Print the counter after >10M iterations
30>>> cnt
310