#27111: [Python]import math 或 functools.reduce


406490150@gms.tku.edu.tw (我是朱朱)

學校 : 國立交通大學
編號 : 139794
來源 : [140.113.236.122]
最後登入時間 :
2022-09-03 11:13:16
a623. 3. Combination -- HP CodeWars2007 | From: [1.172.229.111] | 發表日期 : 2021-09-13 14:48

In [3]: factorial?

Signature: factorial(x, /)

Docstring:

Find x!.

 

Raise a ValueError if x is negative or non-integral.

Type:      builtin_function_or_method

 

______________________________________

Python 3.8以上版本才有的功能,ZJ是3.6所以不能直接用

In [4]: comb?

Signature: comb(n, k, /)

Docstring:

Number of ways to choose k items from n items without repetition and without order.

 

Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates

to zero when k > n.

 

Also called the binomial coefficient because it is equivalent

to the coefficient of k-th term in polynomial expansion of the

expression (1 + x)**n.

 

Raises TypeError if either of the arguments are not integers.

Raises ValueError if either of the arguments are negative.

 

Type:      builtin_function_or_method

 

__________________________

如果要自己幹,也可以試試functools.reduce

 

 

 
ZeroJudge Forum