Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. def main():
  2. from random import randint
  3. from time import sleep
  4. from replit import clear
  5. from colorama import Fore
  6.  
  7. heads3_tails0 = 0
  8. heads2_tails1 = 0
  9. heads1_tails2 = 0
  10. heads0_tails3 = 0
  11.  
  12. clear()
  13. print(Fore.YELLOW + 'Simulation: Flip Three Coins')
  14. print(Fore.RED + 'This code will simulate flipping 3 coins 1,000 times')
  15. wait = input(Fore.WHITE + '\nPress ENTER to begin the simulation... ')
  16.  
  17. numberOfRounds = 1
  18. flipsInEachRound = 100
  19. eachRound = 0
  20. roundCounter = 0
  21. totalFlips = 0
  22.  
  23. for eachRound in range(numberOfRounds):
  24. clear()
  25. print(Fore.YELLOW + 'Simulation: Flip Three Coins')
  26. print(Fore.RED + '\nRound: ', eachRound + 1 , 'of' , numberOfRounds, '\n')
  27. for roundCounter in range(flipsInEachRound):
  28. totalFlips += 1
  29. #0 = heads, 1 = tails
  30. coin1 = randint(0,1)
  31. coin2 = randint(0,1)
  32. coin3 = randint(0,1)
  33.  
  34. if coin1 == 0 and coin2 == 0 and coin3 == 0:
  35. print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': THREE HEADS')
  36. heads3_tails0 += 1
  37.  
  38. if (coin1 == 0 and coin2 == 0 and coin3 == 1) or (coin1 == 0 and coin2 == 1 and coin3 == 0) or (coin1 == 1 and coin2 == 0 and coin3 == 0):
  39. print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': TWO HEADS and ONE TAIL')
  40. heads2_tails1 += 1
  41.  
  42. if (coin1 == 0 and coin2 == 1 and coin3 == 1) or (coin1 == 1 and coin2 == 1 and coin3 == 0) or (coin1 == 1 and coin2 == 0 and coin3 == 1):
  43. print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': ONE HEAD and TWO TAILS')
  44. heads1_tails2 += 1
  45.  
  46. if coin1 == 1 and coin2 == 1 and coin3 == 1:
  47. print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': THREE TAILS')
  48. heads0_tails3 += 1
  49.  
  50. sleep(0.2)
  51.  
  52. print(Fore.GREEN + '\n\nTOTALS, SO FAR:')
  53. print(Fore.LIGHTGREEN_EX + '\nTHREE HEADS:', heads3_tails0)
  54. print(Fore.LIGHTGREEN_EX + 'TWO HEADS, ONE TAIL', heads2_tails1)
  55. print(Fore.LIGHTGREEN_EX + 'ONE HEAD, TWO TAILS', heads1_tails2)
  56. print(Fore.LIGHTGREEN_EX + 'THREE TAILS:', heads0_tails3)
  57. wait = input(Fore.WHITE + '\n\nPress ENTER to continue... ')
  58.  
  59. clear()
  60. print(Fore.YELLOW + 'Simulation: Flip Three Coins')
  61. print(Fore.RED + '\n\nFINAL RESULTS:')
  62. print(Fore.LIGHTRED_EX + '\nTOTAL NUMBER OF FLIPS:', totalFlips)
  63.  
  64. percent_H3T0 = float(100 * heads3_tails0 / totalFlips)
  65. percent_H2T1 = float(100 * heads2_tails1 / totalFlips)
  66. percent_H1T2 = float(100 * heads1_tails2 / totalFlips)
  67. percent_H0T3 = float(100 * heads0_tails3 / totalFlips)
  68.  
  69. print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nTHREE HEADS:', heads3_tails0, '= %.1f' % percent_H3T0 + '%')
  70. print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nTWO HEADS, ONE TAIL:', heads2_tails1, '= %.1f' % percent_H2T1 + '%')
  71. print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nONE HEAD, TWO TAILS:', heads1_tails2, '= %.1f' % percent_H1T2 + '%')
  72. print(Fore.LIGHTRED_EX + '\n\nTHREE TAILS:', heads0_tails3, '= %.1f' % percent_H0T3 + '%')
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement