Calculates the factorial of a number.
num
is less than or equal to 1
, return 1
.num
and the factorial of num - 1
.num
is a negative or a floating point number.def factorial(num):
if not ((num >= 0) and (num % 1 == 0)):
raise Exception("Number can't be floating point or negative.")
return 1 if num == 0 else num * factorial(num - 1)
factorial(6) # 720
Python, Math
Calculates the greatest common divisor of a list of numbers.
Python, Math
Calculates the average of two or more numbers.
Python, Math
Calculates the number of ways to choose k
items from n
items without repetition and without order.