Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math, random
- #RUN CONDITIONAL ON 60% WINNING MARGIN
- elections = 10000000
- voters = 100
- loses = ties = wins = 0
- for j in range(elections):
- myvote = random.choice([-1,1])
- votes = myvote
- for i in range(voters):
- votes = votes + random.choice([-1,1])
- if votes > 0.6*voters:
- #print('votes:', votes)
- print('myvote:', myvote)
- if votes * myvote < 0:
- #print('LOST')
- loses = loses + 1
- if votes * myvote == 0:
- #print('TIED')
- ties = ties + 1
- if votes * myvote > 0:
- #print('WON')
- wins = wins + 1
- print('elections',elections)
- print('loses',loses)
- print('ties',ties)
- print('wins',wins)
- #RUN AS A RANDOM VOTER SAMPLE
- ##elections = 100000
- ##voters = 1000
- ##loses = ties = wins = 0
- ##for j in range(elections):
- ## votes = 0
- ## for i in range(voters):
- ## votes = votes + random.choice([-1,1])
- ## myvote = random.randrange(-voters, voters)
- ## #print('votes:', votes)
- ## #print('myvote:', myvote)
- ## if votes*myvote > votes*votes:
- ## #print('LOST')
- ## loses = loses + 1
- ## if votes == 0:
- ## #print('TIED')
- ## ties = ties + 1
- ## if votes*myvote < votes*votes:
- ## #print('WON')
- ## wins = wins + 1
- ##print('elections',elections)
- ##print('loses',loses)
- ##print('ties',ties)
- ##print('wins',wins)
- #REGULAR RUN
- ##elections = 100000
- ##voters = 1000
- ##loses = ties = wins = 0
- ##for j in range(elections):
- ## myvote = random.choice([-1,1])
- ## votes = myvote
- ## for i in range(voters):
- ## votes = votes + random.choice([-1,1])
- ## #print('votes:', votes)
- ## #print('myvote:', myvote)
- ## if votes * myvote < 0:
- ## #print('LOST')
- ## loses = loses + 1
- ## if votes * myvote == 0:
- ## #print('TIED')
- ## ties = ties + 1
- ## if votes * myvote > 0:
- ## #print('WON')
- ## wins = wins + 1
- ##print('elections',elections)
- ##print('loses',loses)
- ##print('ties',ties)
- ##print('wins',wins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement