Método Python math.factorial()
Ejemplo
Encuentra el factorial de un número:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
Definición y uso
El math.factorial()
método devuelve el factorial de un número.
Nota: este método solo acepta números enteros positivos.
El factorial de un número es la suma de la multiplicación de todos los números enteros, desde nuestro número especificado hasta 1. Por ejemplo, el factorial de 6 sería 6 x 5 x 4 x 3 x 2 x 1 = 720
Sintaxis
math.factorial(x)
Valores paramétricos
Parameter | Description |
---|---|
x | Required. A positive integer. If the number is negative, or not an integer, it returns a ValueError. If the value is not a number, it returns a TypeError |
Detalles técnicos
Valor devuelto: | int Un valor positivo |
---|---|
Versión de Python: | 2.6 |