Created
November 11, 2013 23:47
-
-
Save shiumachi/7422686 to your computer and use it in GitHub Desktop.
当たりが1つしかないくじ引きの確率
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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