def fact(n): if n == 0: return 1 else: return n * fact(n-1) def nways(dice): nsides = 10.0 thresh = 4.0 hist = [] for nsucs in range(0,dice+1): for ndice in range(1,dice+1): nonsucs = ndice - nsucs if (nonsucs >= 0): sucprob = thresh/nsides nsucprob = (nsides-thresh)/nsides a = sucprob**nsucs b = nsucprob**nonsucs sucperm = fact(ndice)/(fact(nsucs)*fact(ndice-nsucs)) nwaysn = (a*b)*sucperm print nwaysn, elif (nonsucs < 0): print 0, print '' return 0 nways(10)