# Count how many times it takes to get 3 consecutive heads from random import randint HEADS=0 TAILS=1 GOAL = 10 headCount = 0 numFlips = 0 while headCount < GOAL: side = randint(0,1) numFlips += 1 if side == HEADS: headCount += 1 print "H", else: # it's TAILS headCount = 0 print "T", print "\nThe number of flips to reach three consecutive heads is", numFlips