1 def C(n, i): 2 #isinstance(object, classinfo) 3 #如果参数object是classinfo的实例,或者object是classinfo类的子类的一个实例, 4 #返回True。如果object不是一个给定类型的的对象, 则返回结果总是False。 5 if not (isinstance(n, int) and isinstance(i, int) and n >= i): 6 print('n and i must be integers and n must be larger than or qual to i.') 7 return 8 result = 1 9 Min, Max = sorted((i, n - i)) 10 for i in range(n, 0, -1): 11 if i > Max: 12 result *= i 13 elif i <= Min: 14 result /= i 15 return result 16 17 print(C(4, 2))