jmu-python-组合数

def Factorial(n):
    s = 1
    for i in range(1,n+1):
        s = s * i
    return s
 
def cal(m,n):
    n_1 = Factorial(n)
    m_1 = Factorial(m)
    n_m = Factorial(n-m)
    return n_1 / (m_1 * n_m)
 
def judge(m,n):
    try:
        m, n = int(m), int(n)
        return True
    except:
        return False
 
m,n = input().split()
if judge(m,n):
    m, n = int(m), int(n)
    if m > 0 and n > 0:
        print('result={:.2f}'.format(cal(m, n)))
    else:
        print('不能负数')
else:

 

posted @ 2020-06-21 16:30  tf383838  阅读(301)  评论(0编辑  收藏  举报