Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

After working your way through the Chapter 3, you are now going to create a prog

ID: 77409 • Letter: A

Question

After working your way through the Chapter 3, you are now going to create a program. Your program will simulate flipping a coin 100 times, and then reveal the number of heads and the number of tails. I would suggest creating your logic with either a flowchart or psuedocode - or both before trying to write this program. Remember to use plenty of comments so you and I both know what you are doing in your program.

Explanation / Answer

> > import random > > > > # set the coin > > > headsCount = 0 > > tailsCount = 0 > > count = 0 > > > > # the loop > > while count < 100: #If > you declare count = 0. The while loop condition should be less than > 100.Else you will get 101 counts. > > *coin = random.randrange(2)* > > if coin == 0: > > headsCount += 1 > > else: #Becase We > already declared randrange(2).So the coin value is 0 or 1.So we can use else > condition. > > tailsCount += 1 > > count += 1 > > > > > > print "The number of heads was", headsCount > > print "The number of tails was", tailsCount > > > > raw_input(" Press the enter key to exit.")