Metoda Python math.factorial().
Příklad
Najděte faktoriál čísla:
#Import math Library
import math
#Return factorial of a number
print(math.factorial(9))
print(math.factorial(6))
print(math.factorial(12))
Definice a použití
Metoda math.factorial()
vrací faktoriál čísla.
Poznámka: Tato metoda přijímá pouze kladná celá čísla.
Faktoriál čísla je součtem násobení všech celých čísel od našeho zadaného čísla až po 1. Například faktoriál 6 by byl 6 x 5 x 4 x 3 x 2 x 1 = 720
Syntax
math.factorial(x)
Hodnoty parametrů
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 |
Technické údaje
Návratová hodnota: | Kladná int hodnota |
---|---|
Verze Pythonu: | 2.6 |