Here is the answer of second question
Here is the answer of question 3
Here is the answer for question 4.
Here is the final code after all three questions
def HTcounts(flips):
#counter to count nH and nT
nH=0
nT=0
#traverse the list
for i in range(len(flips)):
if flips[i]=='H':
nH=nH+1
else:
nT=nT+1
#tuple of answer
booleans=(nH,nT)
#return tuple
return booleans
#test program
#count total head and tail for averaging
headcount=0
tailcount=0
print('Sample run')
print('Trial 1')
print("coin toss result: ['H','H','H','T','T']")
nH,nT=HTcounts(['H','H','H','T','T'])
headcount=headcount+nH
tailcount=tailcount+nT
print('the number of head is ',nH,'and the number of tails is
',nT)
#Trial 2
print('Trial 2')
print("coin toss result: ['H','H','H','H','T']")
nH,nT=HTcounts(['H','H','H','H','T'])
headcount=headcount+nH
tailcount=tailcount+nT
print('the number of head is ',nH,'and the number of tails is
',nT)
#Trial 3
print('Trial 3')
print("coin toss result: ['H','T','T','H','T']")
nH,nT=HTcounts(['H','T','T','H','T'])
headcount=headcount+nH
tailcount=tailcount+nT
print('the number of head is ',nH,'and the number of tails is
',nT)
#Trial 4
print('Trial 4')
print("coin toss result: ['H','T','H','T','T']")
nH,nT=HTcounts(['H','T','H','T','T'])
headcount=headcount+nH
tailcount=tailcount+nT
print('the number of head is ',nH,'and the number of tails is
',nT)
print("The avg number of heads is ",headcount/4,"and the number of
tails is ",tailcount/4)
00 1- def HTcounts(flips): 2 #counter to count nH and nt 3 nH=0 4 nT=0 5 #traverse the list 6 for i in range(len(flips)): 7- if flips[i]=='H': nH nH+1 9 else: 10 nT=nT+1 11 #tuple of answer 12 booleans=(nH,nT) #return tuple 14 return booleans 15 #test program 16 print('Sample run') 17 nH,nT=HT counts(['H', 'H', 'H', 'H','T']) 18 print('For the Sample coin toss of 5 coins already made') 19 print('the number of head is ',nH, 'and the number of tails is ',NT) 13 input For the Sample coin toss of 5 coins already made the number of head is 4 and the number of tails is 1
Nmin 000 1- def HTcounts(flips): #counter to count nH and nt nH=0 nT=0 #traverse the list 6 for i in range(len(flips)): if flips[i]=='H': nH nH+1 9- else: 10 nT=nT+1 11 #tuple of answer 12 booleans=(nH, nT) 13 #return tuple 14 return booleans 15 #test program 16 print('Sample run') 17 print('Trial 1') 18 print("coin toss result: ['H', 'H', 'H','T','T']") 19 nH, nT=HT counts(['H', 'H', 'H', 'T', 'T']) 20 print('the number of head is ',nH, 'and the number of tails is ',NT) 21 #Trial 2 22 print('Trial 2') 23 print("coin toss result: ['H', 'H', 'H', 'H', 'T']") 24 nH, nT=HT counts(['H', 'H', 'H', 'H','T']) 25 print('the number of head is ',nH, 'and the number of tails is ',NT) 26 #Trial 3 27 print('Trial 3') 28 print("coin toss result: ['H','T','T', 'H', 'T']") 29 nH,nT=HTcounts(['H', 'I' 'T', 'H', 'T']). S
27 print Trial 28 print("coin toss result: ['H','T', 'T', 'H', 'T']") 29 H,nT=HT counts(['H', 'T', 'T', 'H','T']) 30 print('the number of head is ', nH, 'and the number of tails is ',NT) 31 #Trial 4 32 print('Trial 4')|| 33 print("coin toss result: ['H','T', 'H','T', 'T']") 34 nH, nT=HT counts(['H', 'T', 'H','T', 'T']) 35 print('the number of head is ',nH, 'and the number of tails is ',NT) 36 37 input Sample run Trial 1 coin toss result: ['H', 'H', 'H', 'T', 'T'] the number of head is 3 and the number of tails is 2 Trial 2 coin toss result: ['H', 'H', 'H', 'H', 'T'] the number of head is 4 and the number of tails is 1 Trial 3 coin toss result: ['H', 'T','T', 'H','T'] the number of head is 2 and the number of tails is 3 Trial 4 coin toss result: ['H', 'T', 'H', 'T', 'T'] the number of head is 2 and the number of tails is 3
1. def HTcounts(flips): 2 #counter to count nH and nt nH=0 4 nT=0 5 #traverse the list 6 for i in range(len(flips)): 7- if flips[i]=='H': nH nH+1 9 else: 10 nT=nT+1 11 #tuple of answer 12 booleans=(nH,NT) 13 #return tuple 14 return booleans 15 #test program 16 #count total head and tail for averaging 17 headcount=0 18 tailcount=0 19 print("Sample run') 20 print('Trial 1') 21 print("coin toss result: ['H', 'H', 'H','T', 'T']") 22 nH,nT=HT counts(['H', 'H', 'H','T','T']) 23 headcount=headcount+nH 24 tailcount=tailcount+nT 25 print('the number of head is ',nH, 'and the number of tails is ',NT) 26 #Trial 2 27 print('Trial 2') 28 print("coin toss result: ['H', 'H', 'H', 'H', 'T']") 29 nH,nT=HT counts(['H', 'H', 'H', 'H','T']) 30 headcount=headcount+nH input
28 print("coin toss result: ['H', 'H', 'H', 'H', 'T']") 29 nH,nT=HT counts(['H', 'H', 'H', 'H','T']) 30 headcount=headcount+nH 31 tailcount=tailcount+nT 32 print('the number of head is ',nH, 'and the number of tails is ',NT) 33 #Trial 3 34 print('Trial 3') 35 print("coin toss result: ['H','T', 'T', 'H', 'T']") 36 nH,nT=HT counts(['H', 'T', 'T', 'H','T']) 37 headcount=headcount+nH 38 tailcount=tailcount+nT 39 print('the number of head is ',nH, 'and the number of tails is ',NT) 40 #Trial 4 41 print('Trial 4') 42 print("coin toss result: ['H', 'T','H','T', 'T'l") 43 nH,nT=HT counts(['H','T', 'H','T','T']) 44 headcount=headcount+nH 45 tailcount=tailcount+nT 46 print('the number of head is ',nH, 'and the number of tails is ',NT) 47 print("The avg number of heads is ", headcount/4, "and the number of tails is ", tailcount/4) 48 49 50 51
input Sample run Trial 1 coin toss result: ['H', 'H', 'H', 'T', 'T'] the number of head is 3 and the number of tails is 2 Trial 2 coin toss result: ['H', 'H', 'H', 'H', 'T'] the number of head is 4 and the number of tails is 1 Trial 3 coin toss result: ['H', 'T','T', 'H', 'T'] the number of head is 2 and the number of tails is Trial 4 coin toss result: ['H', 'T', 'H', 'T', 'T'] the number of head is 2 and the number of tails is 3 The avg number of heads is 2.75 and the number of tails is 3 2.25 ... Program finished with exit code 0 Press ENTER to exit console.
2. . Write the function below per the docstring. A tuple is simply comma separated data....
Flipping Coins For a fair coin, the chance of getting tails is 1/2. Counting the number of tails Let's experiment with the total number of tails in n trials. Total number of tails in a small number of coin flips ם Suppose we flip 10 coins (with 1 = Tails and 0 = Heads). Here are six samples of size 10. = 10 trials = 6 for (i in 1: trials) { print (sample(c(0, 1), 1, replace=TRUE)) مه ## [1]...
Flipping Coins For a fair coin, the chance of getting tails is 1/2. Counting the number of tails Let's experiment with the total number of tails in n trials. Total number of tails in a small number of coin flips n Suppose we flip 10 coins (with 1 = Tails and 0 = Heads). Here are six samples of size 10. - 10 trials = 6 for (i in 1: trials) { print (sample(c(0, 1), n, replace=TRUE)) ## [1] 0...
Fraction of tails Now let's look at the fraction of tails in n trials. Fraction of tails in a small number of coin flips Tails and 0 = Heads). n Suppose we Aip 10 coins and compute the fraction of tails (with 1 = - 10 trials - 6 for (i in 1: trials) { print (sun (sample(c(0, 1), n, replace=TRUE)) / n) 3 ## (1) 0.1 ## (1) 0.4 ## [1] 0.4 ## [1] 0.5 ## (1) 0.7 ##...
Using c++ Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2. 1 represents heads and 2 represents tails. Exercise 1 (40 points) Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2.1 represents heads and 2 represents tails Use the function...
Write a program that simulates the toss of a coin. Whenever a coin is tossed the result will be either a head or tail. Prompt the user as shown by entering an ‘H’ for heads or ‘T’ for tails. Use a loop for input validation of an ‘h’ or ‘t’. Make sure that both an upper case and lower case will be accepted. Have the computer generate a random number. Assign a char variable a (‘h’ ^ ’t’) head or...
Weekly Experiment and Discussion - Part 1 Take 2 coins and flip "together" 50 times Tally each set of flips and report the frequencies in the format shown below: 2nd coin Heads 2nd coin tails 1st coin Heads # of (H, H) # of (H, T) 1st coin Tails # of (T, H) # of (T, T) (e.g., if on 12 occasions both coins were heads, there should be a 12 in the top left box) Weekly Experiment and Discussion...
Fraction of tails Now let's look at the fraction of tails in n trials. Fraction of tails in a small number of coin flips Heads) Suppose we flip 10 coins and compute the fraction of tails (with 1 = Tails and 0 = = 10 trials = 6 for (i in 1: trials) { print (sum(sample(c(0, 1), n, replace-TRUE)) /n) ## [1] 0.1 ## [1] 0.4 ## [1] 0.4 ## (1) 0.5 ## [1] 0.7 *# (1) 0.6 The expected...
A box contains five coins. For each coin there is a different probability that a head will be obtained when the coin is tossed. (Some of the coins are not fair coins!) Let pi denote the probability of a head when the i th coin is tossed (i = 1, . . . , 5), and suppose that p1 = 0, p2 =1/4, p3 =1/2, p4 =3/4, p5 =1. The experiment we are interested in consists in selecting at random...
Step 1: Declare a base class called Coin that contains a Boolean data element called face, and a random generator to fill the face element with a Boolean value (true or false). True = heads, false = tails. The class needs a default constructor, a method to flip the coin, a method to return the face element, and a toString to display “Heads” if the face is true and “Tails” if not. Step 2: Declare a subclass of Coin that...
Complete the table and graph the cumulative relative frequency of heads MR. Harrison tossed a coin 25 times resulting in 10 tails. Complete the result in the following table and graph the commulative relatiove frequency of he Commulative relative frequency of H Commulative frequency Toss Number outcome(H or T) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 MR. Harrison tossed a coin 25 times resulting in 10 tails....