from random import randint s=0 for k in range(1000): d=randint(1,2) if d==2: s=s+1 f=s/1000 print(f)