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

Part 3: HHT or HTT? Suppose we have a fair coin, where the probability of heads

ID: 3728669 • Letter: P

Question

Part 3: HHT or HTT? Suppose we have a fair coin, where the probability of heads (H) is 0.5 and the probability of tails (T) is 0.5. We know from probability that if we flip the coin three times, any of the eight possible coin toss sequences is equally likely to appear. This problem concerns, rather than three coin flips, the situation where we flip coins until a certain coin toss sequence appears "Flip a coin until either HHT or HTT appears. Is one more likely to appear first? If so, which one and with what probability? Simulate this problem to estimate the probability that HHT appears first and the probability that HTT appears first. Question 3.0 In order to do the simulation, we need to generate coin flips. Write a function called generate flips that keep generating flips until either HTT or HHT appears. This function should return HTT or HHT, whichever appears first. 36]: def generate_flips) o: generate_flips()

Explanation / Answer

import random def generate_flips(): #HHT means 110 = 6 in decimal #HTT means 100 = 4 in decimal while(True): c = random.randint(1, 8) if(c == 6): return "HHT" if(c == 4): return "HTT" return ""