Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import math, random
  2.  
  3. #RUN CONDITIONAL ON 60% WINNING MARGIN
  4. elections = 10000000
  5. voters = 100
  6. loses = ties = wins = 0
  7. for j in range(elections):
  8. myvote = random.choice([-1,1])
  9. votes = myvote
  10. for i in range(voters):
  11. votes = votes + random.choice([-1,1])
  12. if votes > 0.6*voters:
  13. #print('votes:', votes)
  14. print('myvote:', myvote)
  15. if votes * myvote < 0:
  16. #print('LOST')
  17. loses = loses + 1
  18. if votes * myvote == 0:
  19. #print('TIED')
  20. ties = ties + 1
  21. if votes * myvote > 0:
  22. #print('WON')
  23. wins = wins + 1
  24. print('elections',elections)
  25. print('loses',loses)
  26. print('ties',ties)
  27. print('wins',wins)
  28.  
  29.  
  30.  
  31.  
  32. #RUN AS A RANDOM VOTER SAMPLE
  33. ##elections = 100000
  34. ##voters = 1000
  35. ##loses = ties = wins = 0
  36. ##for j in range(elections):
  37. ## votes = 0
  38. ## for i in range(voters):
  39. ## votes = votes + random.choice([-1,1])
  40. ## myvote = random.randrange(-voters, voters)
  41. ## #print('votes:', votes)
  42. ## #print('myvote:', myvote)
  43. ## if votes*myvote > votes*votes:
  44. ## #print('LOST')
  45. ## loses = loses + 1
  46. ## if votes == 0:
  47. ## #print('TIED')
  48. ## ties = ties + 1
  49. ## if votes*myvote < votes*votes:
  50. ## #print('WON')
  51. ## wins = wins + 1
  52. ##print('elections',elections)
  53. ##print('loses',loses)
  54. ##print('ties',ties)
  55. ##print('wins',wins)
  56.  
  57.  
  58.  
  59.  
  60.  
  61. #REGULAR RUN
  62. ##elections = 100000
  63. ##voters = 1000
  64. ##loses = ties = wins = 0
  65. ##for j in range(elections):
  66. ## myvote = random.choice([-1,1])
  67. ## votes = myvote
  68. ## for i in range(voters):
  69. ## votes = votes + random.choice([-1,1])
  70. ## #print('votes:', votes)
  71. ## #print('myvote:', myvote)
  72. ## if votes * myvote < 0:
  73. ## #print('LOST')
  74. ## loses = loses + 1
  75. ## if votes * myvote == 0:
  76. ## #print('TIED')
  77. ## ties = ties + 1
  78. ## if votes * myvote > 0:
  79. ## #print('WON')
  80. ## wins = wins + 1
  81. ##print('elections',elections)
  82. ##print('loses',loses)
  83. ##print('ties',ties)
  84. ##print('wins',wins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement