from random import randint N = 100 M = 0 for i in range(N): r = randint(0,1) if r == 0: print('head') M+=1 else: print('tail') print('Number of heads ',M) """ Terminal> python flip_coin.py head tail head ... head tail tail head tail tail tail Number of heads 51 """