Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created November 11, 2013 23:47
Show Gist options
  • Save shiumachi/7422686 to your computer and use it in GitHub Desktop.
Save shiumachi/7422686 to your computer and use it in GitHub Desktop.
当たりが1つしかないくじ引きの確率
def f(num, max_num):
"""
num: くじを引く回数
max_num: くじの総数
"""
p = 1.0
for i in xrange(num):
p = p * (float(max_num - i - 1) / (max_num - i))
return p
def g(num, max_num):
q = (1 - f(num, max_num)) * 100
return "{0:.2f}%".format(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment