Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- from random import randint
- from time import sleep
- from replit import clear
- from colorama import Fore
- heads3_tails0 = 0
- heads2_tails1 = 0
- heads1_tails2 = 0
- heads0_tails3 = 0
- clear()
- print(Fore.YELLOW + 'Simulation: Flip Three Coins')
- print(Fore.RED + 'This code will simulate flipping 3 coins 1,000 times')
- wait = input(Fore.WHITE + '\nPress ENTER to begin the simulation... ')
- numberOfRounds = 1
- flipsInEachRound = 100
- eachRound = 0
- roundCounter = 0
- totalFlips = 0
- for eachRound in range(numberOfRounds):
- clear()
- print(Fore.YELLOW + 'Simulation: Flip Three Coins')
- print(Fore.RED + '\nRound: ', eachRound + 1 , 'of' , numberOfRounds, '\n')
- for roundCounter in range(flipsInEachRound):
- totalFlips += 1
- #0 = heads, 1 = tails
- coin1 = randint(0,1)
- coin2 = randint(0,1)
- coin3 = randint(0,1)
- if coin1 == 0 and coin2 == 0 and coin3 == 0:
- print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': THREE HEADS')
- heads3_tails0 += 1
- 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):
- print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': TWO HEADS and ONE TAIL')
- heads2_tails1 += 1
- 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):
- print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': ONE HEAD and TWO TAILS')
- heads1_tails2 += 1
- if coin1 == 1 and coin2 == 1 and coin3 == 1:
- print(Fore.LIGHTBLUE_EX + 'Flip ' + str(totalFlips) + ': THREE TAILS')
- heads0_tails3 += 1
- sleep(0.2)
- print(Fore.GREEN + '\n\nTOTALS, SO FAR:')
- print(Fore.LIGHTGREEN_EX + '\nTHREE HEADS:', heads3_tails0)
- print(Fore.LIGHTGREEN_EX + 'TWO HEADS, ONE TAIL', heads2_tails1)
- print(Fore.LIGHTGREEN_EX + 'ONE HEAD, TWO TAILS', heads1_tails2)
- print(Fore.LIGHTGREEN_EX + 'THREE TAILS:', heads0_tails3)
- wait = input(Fore.WHITE + '\n\nPress ENTER to continue... ')
- clear()
- print(Fore.YELLOW + 'Simulation: Flip Three Coins')
- print(Fore.RED + '\n\nFINAL RESULTS:')
- print(Fore.LIGHTRED_EX + '\nTOTAL NUMBER OF FLIPS:', totalFlips)
- percent_H3T0 = float(100 * heads3_tails0 / totalFlips)
- percent_H2T1 = float(100 * heads2_tails1 / totalFlips)
- percent_H1T2 = float(100 * heads1_tails2 / totalFlips)
- percent_H0T3 = float(100 * heads0_tails3 / totalFlips)
- print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nTHREE HEADS:', heads3_tails0, '= %.1f' % percent_H3T0 + '%')
- print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nTWO HEADS, ONE TAIL:', heads2_tails1, '= %.1f' % percent_H2T1 + '%')
- print(Fore.LIGHTRED_EX + Fore.LIGHTRED_EX + '\n\nONE HEAD, TWO TAILS:', heads1_tails2, '= %.1f' % percent_H1T2 + '%')
- print(Fore.LIGHTRED_EX + '\n\nTHREE TAILS:', heads0_tails3, '= %.1f' % percent_H0T3 + '%')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement