Design a well-documented, Python function coinToss(N) to simulate the experiment
ID: 3750044 • Letter: D
Question
Design a well-documented, Python function coinToss(N) to simulate the experiment of tossing 100 unbiased, fair coins in N trials. Record the number of times that the number of coins is exactly firty heads for each trial. HEAD TAIL #1. Simulate 100 Fair Coins Tossed 95 96 97 899 100 46 47 48 2. Count How Many Heads #3. Success is Defined when EXACTLY SO Heads is simulated NO SUCCESS 95 96 97 899 100 48 49 50 SUCCESS Have the function coinToss(N) return the number of times exactly fifty heads accurred divided by the number of trials In the illustration below, coinTossi(5) returns 2/5 to the calling program because in two of the ive trials exactly fifty heads was observed twice.Explanation / Answer
# IMPORTS
import random
# Globals
CoinSideNames = ""
# FUNCTIONS
def CoinFlip():
CoinSide = random.randint(-1,1)
while CoinSide == 0 :
CoinSide = random.randint(-1,1)
print ("Inside Function CoinSide ", CoinSide)
CoinSideName(CoinSide)
def CoinSideName(CoinSide):
print ("Inside Function CoinSideName ******")
if CoinSide == -1 :
CoinSideNames ="Tails"
print ("Inside Function CoinSideName ", CoinSideNames)
elif CoinSide == 1 :
CoinSideNames ="Heads"
print ("Inside Function CoinSideName ", CoinSideNames)
return CoinSideNames
# START
print("Welcome to my Coin flip game")
command=""
while command != "Exit" or command != "e" or command != "E" :
command = input("Choose Heads, Tails,Start or Exit.")
if command =="Exit" or command =="exit" or command =="E" or command =="e" :
break
CoinFlip()
print("The Coin Landed Showing " + CoinSideNames)
coin toss game
print (" COIN TOSS SIMULATION MENU")
print (" --------------------------------------")
print (" a)Simulate 100 coin Tosses")
print (" q)Quit the program")
selection = input(" Please make a selection: ")
if(selection == 'a'):
else import random
main def ()
count = 0
heads = 0
tails = 0
while (count < 100):
flip = random.randrange (0,1)
if flip == 1:
heads +=1
print "heads"
elif flip == 0
tails += 1
print "tails"
print ("COIN TOSS STATISTICS")
print ("---------------------")
print("Result")
print("--------")
print("Number of heads:")
print heads
print("Number of tails:")
print tails
if (selection == 'q'):
elif print ( "press any keys to exit")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.